Solved

check for file

Posted on 2002-07-02
3
134 Views
Last Modified: 2010-05-02
hello,

can anyone tell me, how can check if a file exists?

thanks
0
Comment
Question by:kkarnez
3 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 50 total points
Comment Utility
if dir("yourfile") = empty then
  'file does not exist
else
  'file does exist
end if

CHeers
0
 
LVL 5

Expert Comment

by:rpai
Comment Utility
Dim fso as Object

Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(filespec)) Then
    debug.print filespec & " exists."
Else
    debug.print filespec & " doesn't exist."
End If
 
0
 
LVL 3

Expert Comment

by:schworak
Comment Utility
Both of the above methods work well.

If you are only checking to see if the file exists the first method is faster than creating the scripting object then dropping it. If you are going to do a lot of file stuff then use the second method and keep the file system object around in your program so you don't need to keep recreating it.

If you are going to read from the file you can also just open it and check for an error (this is the fastest way if you are going to use the file when it exists)

on error resume next
open "yourfile" for input as #1
if err=0 then
   '
   ' your code goes here
   '
   close #1
end if
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…

744 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

16 Experts available now in Live!

Get 1:1 Help Now