VB and VBA Users Source Code: Check if a Directory Exists
[
Home
|
Contents
|
Search
|
Reply
| Previous |
Next
]
VB/VBA Source Code
Check if a Directory Exists
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Thursday, August 17, 2000
Hits:
911
Category:
Files/Directories/IO
Article:
The following code checks if a folder/directory exists without using Dir. I recommend not using the Dir function to check if a directory exists, since it can return a result even if you pass in an empty string or other special characters. 'Purpose : Check if a directory/path exists 'Inputs : sPath The path to check 'Outputs : Returns True if the path exists, False if it doesn't 'Author : Andrewb 'Date : 17/08/2000 'Notes : 'Revisions : Function DirExists(ByVal sPath As String) As Boolean If sPath <> ".." And sPath <> "." And sPath <> "\" And Len(sPath) > 0 Then If Right$(sPath, 1) <> "\" Then sPath = sPath & "\" End If On Error Resume Next DirExists = (GetAttr(sPath) And vbDirectory) > 0 On Error GoTo 0 End If End Function
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder