Option Explicit
Declare PtrSafe Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As LongPtr
Declare PtrSafe Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As LongPtr, lpFindFileData As WIN32_FIND_DATA) As Long
Declare PtrSafe Function FindClose Lib "kernel32" (ByVal hFindFile As LongPtr) As Long
Public Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Public 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
Sub ListFilesInSystemVolumeInformation()
Dim hFindFile As LongPtr
Dim findData As WIN32_FIND_DATA
Dim fileName As String
' Spécifiez le chemin du répertoire System Volume Information
fileName = "C:\System Volume Information\*"
' Trouver le premier fichier dans le répertoire
hFindFile = FindFirstFile(fileName, findData)
' Vérifier si un fichier a été trouvé
If hFindFile <> 0 Then
Do
' Afficher le nom du fichier
Debug.Print TrimNull(findData.cFileName)
' Trouver le prochain fichier
Loop While FindNextFile(hFindFile, findData) = 0
' Fermer la recherche
FindClose hFindFile
Else
Debug.Print "Aucun fichier trouvé."
End If
End Sub
Function TrimNull(ByVal str As String) As String
Dim pos As Integer
pos = InStr(str, vbNullChar)
If pos > 0 Then
TrimNull = Left(str, pos - 1)
Else
TrimNull = str
End If
End Function