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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

check a file 2

Status
Not open for further replies.

5679

Programmer
Feb 14, 2003
32
AU
I have a folder named "Pictures" containing gif files.
Suppose I want to insert the file "New.gif" in that folder.
How do I check whether a file with the name "New.gif" already exists in the folder "Pictures".
 

Look up the Dir function...
[tt]
If Dir(YourPathFileName) = vbNullString Then 'file does not exist
Else
End If
[/tt]

Good Luck

 
I prefer
Public Function FileExist(a_file As String) As Boolean
On Error GoTo FileExist_Err
FileExist = False
FileExist = ((GetAttr(a_file) And vbDirectory) = 0)
On Error GoTo 0
Exit Function
FileExist_Err:
End Function

which return true if file (with full path) exist otherwise false. Error checking is needed in case that there's no file.
In case that a_file is a directory return false.
Bye
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top