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
| Function liste_mes_Fichiers(path As String, Optional T As Variant = Null, Optional ExT As Variant = 0, Optional a As Long = 0)
Dim itemVU As String, folder As Variant, dirCollection As Collection, i As Long
Set dirCollection = New Collection
If IsNull(T) Then T = Array()
crit = vbDirectory Or vbHidden Or vbNormal Or vbArchive Or vbReadOnly Or vbSystem Or vbVolume
On Error GoTo passe
itemVU = Dir(path, crit)
'Debug.Print IsArray(ExT)
'Explore le dossier courant (path)
Do Until itemVU = vbNullString
'si ce n'est pas un dossier on ajoute le fichier a la liste
If Left(itemVU, 1) <> "." And Not path Like "*RECYCLE*" Then
If (GetAttr(path & itemVU) And vbDirectory) <> vbDirectory Then
'Debug.Print Right(itemVU, 4)
If IsArray(ExT) Then
For i = 0 To UBound(ExT)
If itemVU Like "*" & ExT(i) Then
ReDim Preserve T(0 To a): T(a) = path & itemVU: a = a + 1:
End If
Next
Else
ReDim Preserve T(0 To a): T(a) = path & itemVU: a = a + 1:
End If
End If
End If
'ajout des dossiers enfant direct de la racine a la collection
If Left(itemVU, 1) <> "." And (GetAttr(path & itemVU) And vbDirectory) = vbDirectory Then
dirCollection.Add itemVU
End If
itemVU = Dir()
Loop
passe:
Err.Clear
'Exploration des sudossier inscrit dans la collection
For Each folder In dirCollection
'Debug.Print "---SubDirectory: " & directory & "---"
liste_mes_Fichiers path & folder & "\", T, ExT, a
Next folder
liste_mes_Fichiers = T
End Function |
Partager