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

Find out if a file exists

Status
Not open for further replies.

Helen1greece

Technical User
Jun 4, 2003
85
GR
Is there a way to find out if a file which I know its name and its path exists?
For example...
I want to know if the file: "blah-blah.txt" is in the folder: "c:\My files"
 

try something like....
[tt]
Public Function DoesFileExist(PathNameOfFile As String) As Boolean
If Dir(PathNameOfFile)<> vbNullString Then DoesFileExist = True
End Function
[/tt]

you can test it like so...
[tt]
Option Explicit

Private Sub Form_Load()

MsgBox DoesFileExist(&quot;Your Path File Name Here&quot;)

End Sub

Public Function DoesFileExist(PathNameOfFile As String) As Boolean
If Dir(PathNameOfFile) <> vbNullString Then DoesFileExist = True
End Function
[/tt]


Good Luck

 
You can also use the FileSystemObject and then check for the file existence using its fileexists method
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top