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
|
Option Explicit
Private Fso As Object, Liste As Variant, IndexListe As Integer
Sub ListerLesFichiers()
Dim Debut As String
Debut = ActiveWorkbook.Path ' A adapter
Set Fso = CreateObject("Scripting.FileSystemObject")
IndexListe = 0
ReDim Liste(1, IndexListe)
ListeRecursive Fso.GetFolder(Debut), ".xls"
Application.DisplayAlerts = False
If IndexListe Then
For IndexListe = LBound(Liste, 2) To UBound(Liste, 2)
Debug.Print "Fichier : " & Liste(0, IndexListe) & ", répertoire : " & Liste(1, IndexListe)
Next
End If
Application.DisplayAlerts = True
Set Fso = Nothing
End Sub
Sub ListeRecursive(ByVal f As Object, ByVal ChaineATrouver As String)
Dim Sf As Object, Fich As Object
For Each Sf In f.SubFolders
For Each Fich In Fso.GetFolder(Sf).Files
If InStr(1, LCase(Fich.Name), ChaineATrouver, vbTextCompare) > 0 Then
ReDim Preserve Liste(1, IndexListe)
Liste(0, IndexListe) = Fich.Name
Liste(1, IndexListe) = Fich.Path
IndexListe = IndexListe + 1
End If
Next Fich
ListeRecursive Fso.GetFolder(Sf), ChaineATrouver
Next Sf
End Sub |
Partager