users_user-20.html - [VB] Tester l'existance d'un fichier, d'un dossier et d'un lecteur
- Private Const MAX_PATH As Long = 260
- Private Const INVALID_HANDLE_VALUE As Long = -1
- Private Const FILE_ATTRIBUTE_DIRECTORY As Long = &H10
- 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 * MAX_PATH
- cAlternate As String * 14
- End Type
- Private Declare Function GetLogicalDriveStrings Lib "kernel32" _
- Alias "GetLogicalDriveStringsA" _
- (ByVal nBufferLength As Long, _
- ByVal lpBuffer As String) As Long
- Private Declare Function FindFirstFile Lib "kernel32" _
- Alias "FindFirstFileA" _
- (ByVal lpFileName As String, _
- lpFindFileData As WIN32_FIND_DATA) As Long
- Private Declare Function FindClose Lib "kernel32" _
- (ByVal hFindFile As Long) As Long
- Public Function FolderExists(sFolder As String) As Boolean
- Dim hFile As Long
- Dim WFD As WIN32_FIND_DATA
- sFolder = UnQualifyPath(sFolder)
- hFile = FindFirstFile(sFolder, WFD)
- FolderExists = (hFile <> INVALID_HANDLE_VALUE) And _
- (WFD.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY)
- Call FindClose(hFile)
- End Function
- Private Function UnQualifyPath(ByVal sFolder As String) As String
- sFolder = Trim$(sFolder)
- If Right$(sFolder, 1) = "\" Then
- UnQualifyPath = Left$(sFolder, Len(sFolder) - 1)
- Else
- UnQualifyPath = sFolder
- End If
- End Function
- Public Function FileExists(sSource As String) As Boolean
- Dim WFD As WIN32_FIND_DATA
- Dim hFile As Long
- hFile = FindFirstFile(sSource, WFD)
- FileExists = hFile <> INVALID_HANDLE_VALUE
- Call FindClose(hFile)
- End Function
- Public Function DriveExists(sDrive As String) As Boolean
- Dim sTmp As String
- Dim lBuffersize As Long
- lBuffersize = GetLogicalDriveStrings(0&, sTmp)
- sTmp = Space$(lBuffersize)
- lBuffersize = Len(sTmp)
- If GetLogicalDriveStrings(lBuffersize, sTmp) Then
- DriveExists = InStr(1, sTmp, sDrive, vbTextCompare)
- End If
- End Function
Poster un commentaire