File/Directory/Drive Exists (Updated)
Posted: 2002-06-01
By: ArchiveBot
Viewed: 76
Filed Under:
No attachments for this post
This code returns a true/false if a specified drive/directory/pathname exists.
This is a small, fast routine.
Original Author: Jan Nawara
Inputs
A string containing a pathname must be passed.
If checking for a directory you must also set the second optional argument to True.
Assumptions
'To check if a specific drive letter exists, use strings for the PathName argument that look like this (the strings themselves should not include quotation marks):
'
'"c:"
'"c:"
'
'Eg. DriveStat= File_Exists("c:")
'(NOTE: The backslash is optional.)
'
'To check if a specific directory exists, use strings for the PathName argument that look like this (the strings themselves should not include quotation marks). ALSO, you must use True for the second optional argument, otherwise the function will not work on all directories.:
'
'"c: emp"
'"c:windows"
'
'Eg. DirStat = File_Exists("c: emp", True)
'
'To check if a specific file exists, use strings for the PathName argument that look like this (the strings themselves should not include quotation marks):
'
'"c: empsomefile.exe"
'"c:windows
otepad.exe"
'
'Eg. FileStat = File_Exists("c:windowswin.ini")
Returns
True if the pathname and/or file exists.
Otherwise it returns false.
API Declarations
Code
Function File_Exists(ByVal PathName As String, Optional Directory As Boolean) As Boolean
'Returns True if the passed pathname exist
'Otherwise returns False
If PathName <> "" Then
If IsMissing(Directory) Or Directory = False Then
File_Exists = (Dir$(PathName) <> "")
Else
File_Exists = (Dir$(PathName, vbDirectory) <> "")
End If
End If
End Function
Comments on this post
No comments have been added for this post.
You must be logged in to make a comment.