Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Status Of A file

Posted on 2001-08-03
6
Medium Priority
?
155 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 10

Expert Comment

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

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

Accepted Solution

by:
Nitin Sontakke earned 60 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

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 …
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses

722 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