Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.
File, Folder, Drive Exists
From Wiki
Here are three functions to determine whether a file, folder or drive exists using the FileSystemObject. It is also possible to use Dir to determine if a file or folder exists, however, Dir will return nothing or an error (Runtime Error 52) if you try to check a UNC path.
Note that
FolderExists("C:")
Will return True.
File Exists
Function FileExists(FilePath As String) As Boolean
'The reference for the FileSystemObject Object is Windows Script Host Object Model
'but it not necessary to add the reference for this procedure.
Dim fs As Object
'Assume it does not
FileExists = False
Set fs = CreateObject("Scripting.FileSystemObject")
'FileExists returns True or False
FileExists = fs.FileExists(FilePath)
End Function
Folder Exists
Function FolderExists(DirectoryPath As String) As Boolean
'The reference for the FileSystemObject Object is Windows Script Host Object Model
'but it not necessary to add the reference for this procedure.
Dim fs As Object
'Assume it does not
FolderExists = False
Set fs = CreateObject("Scripting.FileSystemObject")
'FolderExists returns True or False
FolderExists = fs.FolderExists(DirectoryPath)
End Function
Drive Exists
Function DriveExists(DirectoryPath As String) As Boolean
'The reference for the FileSystemObject Object is Windows Script Host Object Model
'but it not necessary to add the reference for this procedure.
Dim fs As Object
'Assume it does not
DriveExists = False
Set fs = CreateObject("Scripting.FileSystemObject")
'DriveExists returns True or False
DriveExists = fs.DriveExists(DirectoryPath)
End Function
Further Information VBE Property: http://msdn2.microsoft.com/en-us/library/6kxy1a51(VS.85).aspx



LTD Social Sitings
Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.