Solved

Status Of A file

Posted on 2001-08-03
6
148 Views
Last Modified: 2010-05-02
Hi, Is there anyway of telling if a file exists? I.E

if "c:\windows\desktop\newfile.text" = "" then
.....
else
.....

Thanks.
0
Comment
Question by:elabiv
6 Comments
 
LVL 22

Expert Comment

by:CJ_S
ID: 6347888
Set a reference to Microsoft Scripting Runtime

Dim fso as Scripting.FileSystemObject
Set fso = New Scripting.FileSystemObject
If(fso.FileExists("c:\windows\desktop\newfile.txt")) Then
  ..
Else
  ..
End If

or instead of the first 2 lines you can use:
Dim fso as Object
Set fso = CreateObject("Scripting.FileSystemObject")

regards,
CJ
0
 
LVL 6

Expert Comment

by:Nitin Sontakke
ID: 6347910
You can also, use:

If Dir("c:\windows\desktop\newfile.text") <> "" Then
   '...
End If
0
 
LVL 6

Accepted Solution

by:
Nitin Sontakke earned 15 total points
ID: 6347913
You can also, use:

If Dir("c:\windows\desktop\newfile.text") <> "" Then
   '--File exists code goes here...
Else
   '--File doesn't exist code goes here...  
End If
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:elabiv
ID: 6347939
My code looks like this;

If Dir(Form1.Text3 & text2.text) <> "" Then
Open Form1.Text3 & text2.text For Append As #newfile
Print #newfile, ; "This is appending"
Close #newfile

Else

Open Form1.Text3 & text2.text For Append As #newfile
Print #newfile, ; "This is writing from scratch"
Close #newfile

But I keep getting an error that says

"File Already Open"

Any ideas?
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 6347954
Are you assigning #newfile = freefile() and ensuring that you close each file handle before attempting the next use thereof. "File Already Open" sounds to me more that it is a problem with the file handles than the file itself.
0
 

Author Comment

by:elabiv
ID: 6347964
Thanks a lot.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question