'===============
'In a Module
'===============
Private Const FILE_ATTRIBUTE_ARCHIVE = &H20
Private Const FILE_ATTRIBUTE_COMPRESSED = &H800
Private Const FILE_ATTRIBUTE_DIRECTORY = &H10
Private Const FILE_ATTRIBUTE_HIDDEN = &H2
Private Const FILE_ATTRIBUTE_NORMAL = &H80
Private Const FILE_ATTRIBUTE_READONLY = &H1
Private Const FILE_ATTRIBUTE_SYSTEM = &H4
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * 260
cAlternate As String * 14
End Type
Private Declare Function FindFirstFile Lib "kernel32.dll" _
Alias "FindFirstFileA" (ByVal lpFileName As String, _
lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindClose Lib "kernel32.dll" _
(ByVal hFindFile As Long) As Long
Public Function DirExists(ByVal str_Dir As String) As Boolean
Dim lng_handle As Long
Dim typ_fileinfo As WIN32_FIND_DATA
'============================================
'In Win95/98/ME, you cannot have an ending
'backslash on a directory, otherwise it
'returns false. I would image its the same
'on WinNT/Win2K
'============================================
If Trim$(Right$(str_Dir, 1)) = "\" Then
str_Dir = Left$(str_Dir, Len(str_Dir) - 1)
End If
lng_handle = FindFirstFile(str_Dir, typ_fileinfo)
If lng_handle = -1 Then
DirExists = False
FindClose lng_handle
Exit Function
Else
If typ_fileinfo.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY Then
DirExists = True
Else
DirExists = False
End If
End If
FindClose lng_handle
End Function