Solved

Status Of A file

Posted on 2001-08-03
6
150 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 9

Expert Comment

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

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

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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MS Access - Capture pressed key onclick 4 46
Excel - Save a copy of work book 13 95
RUNRMTCMD from AS/400 13 122
Excel Macro update each line based on another worksheet 2 52
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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 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…

737 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