hi there anyone know how to check if a directory is on a drive. I am looking for "C:\bakup" and if it is no found the create the directory?
Rohan West
Printable View
hi there anyone know how to check if a directory is on a drive. I am looking for "C:\bakup" and if it is no found the create the directory?
Rohan West
I don't know if there a possibility to test that. But try to create another directory which has the same name. If the MkDir function return an error (Err 58: already exist), you've got you're answer ! :o
PS: I've just see that DirExists does what you want. Thanks to HeSaidJoe
[Edited by (B2F)Tom on 07-11-2000 at 08:52 AM]
here you are:
Code:Private Sub Command1_Click()
If Dir("C:\bakup", vbDirectory) = "" Then
MkDir "C:\bakup"
End If
End Sub
look at your previous post...
Code:
Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" _
(ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
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 * MAX_PATH
cAlternate As String * 14
End Type
Public Const INVALID_HANDLE_VALUE = -1
Public Const FILE_ATTRIBUTE_DIRECTORY = &H10
Public Function UnQualifyPath(ByVal sFolder As String) As String
'trim and remove any trailing slash
sFolder = Trim$(sFolder)
If Right$(sFolder, 1) = "\" Then
UnQualifyPath = Left$(sFolder, Len(sFolder) - 1)
Else: UnQualifyPath = sFolder
End If
End Function
Public Function FolderExists(sFolder As String) As Boolean
Dim hFile As Long
Dim WFD As WIN32_FIND_DATA
'remove training slash before verifying
sFolder = UnQualifyPath(sFolder)
'call the API pasing the folder
hFile = FindFirstFile(sFolder, WFD)
' if a valid file handle was returned, and the directory attribute is set the folder exists
FolderExists = (hFile <> INVALID_HANDLE_VALUE) And _
(WFD.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY)
'clean up
Call FindClose(hFile)
End Function