Click to See Complete Forum and Search --> : Check if file exists


AlexKrat
August 2nd, 2001, 12:31 PM
Is there a good example of how to check if the file with a prticular name already exists.
Also it would be nice to find a good mechanism that automaticaly create a versioned file name like myfile_001 or myfile_002 if myfile and myfile_001 already exist.

Thank you!

Ghost308
August 2nd, 2001, 12:44 PM
Here is a fairly simple method to detect if a file exists or not..


Dim fso
set fso = CreateObject("scripting.FileSystemObject")

If Not fso.FileExists("test.txt") then
msgbox "This file does not exist!"
End if

deghost
August 2nd, 2001, 02:50 PM
An even simple would be:

if Dir(MyFile.txt)<>"" then... 'file exists!




----------
The @host is everywhere!
----------

AlexKrat
August 2nd, 2001, 03:35 PM
this is actualy better

FileName = Dir(path & SearchStr, vbNormal Or vbHidden Or vbSystem _
Or vbReadOnly)




thank you.