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
| Function FindFiles(path As String, SearchStr As String, _
FileCount As Integer, DirCount As Integer)
Dim filename As String ' Walking filename variable.
Dim dirname As String ' SubDirectory Name.
Dim dirNames() As String ' Buffer for directory name entries.
Dim nDir As Integer ' Number of directories in this path.
Dim i As Integer ' For-loop counter.
path = checkPath(path)
' Search for subdirectories.
nDir = 0
ReDim dirNames(nDir)
dirname = Dir(path, vbDirectory Or vbHidden Or vbArchive Or vbReadOnly Or vbSystem)
Do While Len(dirname) > 0
' Ignore the current and encompassing directories.
If (dirname <> ".") And (dirname <> "..") Then
' Check for directory with bitwise comparison.
If GetAttr(path & dirname) And vbDirectory Then
dirNames(nDir) = dirname
DirCount = DirCount + 1
nDir = nDir + 1
ReDim Preserve dirNames(nDir)
'List2.AddItem path & DirName ' Uncomment to list
End If ' directories.
sysFileERRCont:
End If
dirname = Dir() ' Get next subdirectory.
Loop
' Search through this directory and sum file sizes.
filename = Dir(path & SearchStr, vbNormal Or vbHidden Or vbSystem _
Or vbReadOnly Or vbArchive)
Debug.Print filename
While Len(filename) <> 0
FindFiles = FindFiles + FileLen(path & filename)
FileCount = FileCount + 1
l$ = path & filename
n1% = InStr(filename, " - ")
If n1% > 1 Then
aRech$ = Mid$(filename, n1% + 3)
aRech$ = Left$(aRech$, Len(aRech$) - 4) 'enlève extension
cht1$ = Left$(filename, n1% - 1)
r% = -1
Select Case flg$
Case "*.kar", "*.mp3", "*.avi"
Call FindFilesKar
Case "*.wav"
Call FindFilesWav
End Select
End If
filename = Dir() ' Get next file.
Wend
' If there are sub-directories..
If nDir > 0 Then
' Recursively walk into them
For i = 0 To nDir - 1
FindFiles = FindFiles + FindFiles(path & dirNames(i) & "\", _
SearchStr, FileCount, DirCount)
Next i
End If
Exit Function |
Partager