1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
| 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 GetFileAttributes Lib "kernel32" Alias "GetFileAttributesA" (ByVal lpFileName As String) As Long
Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
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
Function trouvefics(chem As String, flt As String, nbf As Integer, nbd As Integer)
Dim nomfic As String, nomdir As String, nds() As String, nDir As Integer, i As Integer, xs As Long
Dim WFD As WIN32_FIND_DATA, ct As Boolean
If Right(chem, 1) <> "\" Then chem = chem & "\"
nDir = 0
ReDim nds(nDir)
ct = True
xs = FindFirstFile(chem & "*", WFD)
If xs <> -1 Then
Do While ct
nomdir = couic0(WFD.cFileName)
If (nomdir <> ".") And (nomdir <> "..") Then
If GetFileAttributes(chem & nomdir) And &H10 Then
nds(nDir) = nomdir: nbd = nbd + 1: nDir = nDir + 1: ReDim Preserve nds(nDir)
End If
End If
ct = FindNextFile(xs, WFD)
Loop
ct = FindClose(xs)
End If
xs = FindFirstFile(chem & flt, WFD)
ct = True
If xs <> -1 Then
While ct
nomfic = couic0(WFD.cFileName)
If (nomfic <> ".") And (nomfic <> "..") Then
trouvefics = trouvefics + (WFD.nFileSizeHigh * &HFFFF) + WFD.nFileSizeLow
nbf = nbf + 1
End If
ct = FindNextFile(xs, WFD)
Wend
ct = FindClose(xs)
End If
If nDir > 0 Then
For i = 0 To nDir - 1
trouvefics = trouvefics + trouvefics(chem & nds(i) & "\", flt, nbf, nbd)
Next i
End If
End Function
Function couic0(chaine0 As String) As String
If (InStr(chaine0, Chr(0)) > 0) Then
chaine0 = Left(chaine0, InStr(chaine0, Chr(0)) - 1)
End If
couic0 = chaine0
End Function |
Partager