- Option Explicit
-
- Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" ( _
- ByVal lpFileName As String, _
- lpFindFileData As WIN32_FIND_DATA) _
- As Long
- Private Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" ( _
- ByVal hFindFile As Long, _
- lpFindFileData As WIN32_FIND_DATA) _
- As Long
- Private Declare Function FindClose Lib "kernel32" ( _
- ByVal hFindFile As Long) _
- As Long
-
- Private Const INVALID_HANDLE_VALUE = -1
- Private Const MAX_PATH = 260
-
- 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
-
-
- '---------------------------------------------------------------------------------------'
- ' Recherche de fichiers '
- '---------------------------------------------------------------------------------------'
- ' '
- ' Path : chemin de départ de la recherche '
- ' fichier : nom du fichier a rechercher '
- ' tabfic() : tableau de retour des fichiers trouvés (avec leur chemin) '
- '---------------------------------------------------------------------------------------'
-
- Public Sub FindFile(path As String, fichier As String, tabfic() As String)
- Dim chemin As String
- Dim fic As String
- Dim hfind As Long
- Dim hfind2 As Long
- Dim struct As WIN32_FIND_DATA
-
- chemin = path
- hfind = FindFirstFile(chemin & "*.*" & Chr(0), struct)
- hfind2 = hfind
- Do Until hfind2 = 0
- If Left(struct.cFileName, 1) <> "." Then
- fic = chemin & Left(struct.cFileName, InStr(struct.cFileName, Chr(0)) - 1)
- Debug.Print fic
- If struct.dwFileAttributes And vbDirectory Then FindFile fic & "\", fichier, tabfic
- If Right(fic, Len(fichier)) = fichier Then
- ReDim Preserve tabfic(UBound(tabfic) + 1)
- tabfic(UBound(tabfic)) = fic
- tabfic(0) = UBound(tabfic)
- End If
- End If
- hfind2 = FindNextFile(hfind, struct)
- Loop
- FindClose hfind
- End Sub
Option Explicit
Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" ( _
ByVal lpFileName As String, _
lpFindFileData As WIN32_FIND_DATA) _
As Long
Private Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" ( _
ByVal hFindFile As Long, _
lpFindFileData As WIN32_FIND_DATA) _
As Long
Private Declare Function FindClose Lib "kernel32" ( _
ByVal hFindFile As Long) _
As Long
Private Const INVALID_HANDLE_VALUE = -1
Private Const MAX_PATH = 260
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
'---------------------------------------------------------------------------------------'
' Recherche de fichiers '
'---------------------------------------------------------------------------------------'
' '
' Path : chemin de départ de la recherche '
' fichier : nom du fichier a rechercher '
' tabfic() : tableau de retour des fichiers trouvés (avec leur chemin) '
'---------------------------------------------------------------------------------------'
Public Sub FindFile(path As String, fichier As String, tabfic() As String)
Dim chemin As String
Dim fic As String
Dim hfind As Long
Dim hfind2 As Long
Dim struct As WIN32_FIND_DATA
chemin = path
hfind = FindFirstFile(chemin & "*.*" & Chr(0), struct)
hfind2 = hfind
Do Until hfind2 = 0
If Left(struct.cFileName, 1) <> "." Then
fic = chemin & Left(struct.cFileName, InStr(struct.cFileName, Chr(0)) - 1)
Debug.Print fic
If struct.dwFileAttributes And vbDirectory Then FindFile fic & "\", fichier, tabfic
If Right(fic, Len(fichier)) = fichier Then
ReDim Preserve tabfic(UBound(tabfic) + 1)
tabfic(UBound(tabfic)) = fic
tabfic(0) = UBound(tabfic)
End If
End If
hfind2 = FindNextFile(hfind, struct)
Loop
FindClose hfind
End Sub