Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to check if a file exists in a directory

Status
Not open for further replies.

bnath005

MIS
Aug 19, 2005
14
US
Set objFSO = CreateObject("Scripting.FileSystemObject")

If the file I am looking for doesn't exist, then the next line is causing an error.

Set objFile = objFSO.GetFile("C:\code\OpicsEod\file.txt")

thanks
much appreciated.
nath
 
If objFSO.FileExists("C:\code\OpicsEod\file.txt") Then
Set objFile = objFSO.GetFile("C:\code\OpicsEod\file.txt")
End If

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
strPath = "C:\code\OpicsEod\file.txt"
If objFSO.FileExists(strPath) Then
Set objFile = objFSO.GetFile(strPath)
...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top