Solved

Status Of A file

Posted on 2001-08-03
6
143 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now