how can I check if a file exists?

Cocoa Dev picture Cocoa Dev · Aug 23, 2011 · Viewed 116k times · Source

I want to check to see if a file exists and if it does, I want to open it and read the 1st line,

If the file doesn't exist or if the file has no contents then I want to fail silently without letting anyone know that an error occurred.

Answer

Helge Klein picture Helge Klein · Aug 23, 2011

Start with this:

Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(path)) Then
   msg = path & " exists."
Else
   msg = path & " doesn't exist."
End If

Taken from the documentation.