Modules |
5.8 Utilizzo della ricorsione per scandire una directory. |
Gianluca Manzi |
Questa funzione fa uso della funzione DIR e restituisce una matrice a 2 colonne contenente il path ed il nome di tutti i file contenuti in una determinata cartella ed in tutte le sue sottodirectory. L'ho creata con Access '97, sinceramente non so se nel 2000 la funzionalità della funzione dir sia stata ampliata o se siano stati aggiunti nuovi metodi x la gestione del file system. Option Compare Database Option Explicit Option Base 1 Private matrice() As String Public Function creamatrice(PATDINIZIO As String) As Variant ReDim matrice(2, 1) If PATDINIZIO Like "?:\" Then caricamatrice PATDINIZIO, True Else caricamatrice PATDINIZIO End If If UBound(matrice, 2) > 1 Then ReDim Preserve matrice(2, UBound(matrice, 2) - 1) End If creamatrice = matrice Erase matrice End Function Private Sub caricamatrice(strpercorso As String, Optional blnIsRoot As Boolean = False) Dim lngcnt2 As Long, lngcnt1 As Long, strnome As String strnome = Dir(strpercorso, vbDirectory) Do While strnome <> "" If blnIsRoot = True And lngcnt1 = 0 Then strnome = Dir(strpercorso, vbDirectory) Else strnome = Dir End If lngcnt1 = lngcnt1 + 1 If strnome <> "" And strnome <> "." And strnome <> ".." Then If GetAttr(strpercorso & strnome) <> vbDirectory Then matrice(1, UBound(matrice, 2)) = strpercorso matrice(2, UBound(matrice, 2)) = strnome ReDim Preserve matrice(2, UBound(matrice, 2) + 1) Else caricamatrice (strpercorso & strnome & "\") strnome = Dir(strpercorso, vbDirectory) lngcnt2 = IIf(blnIsRoot = False, 0, 1) Do While lngcnt2 < lngcnt1 strnome = Dir lngcnt2 = lngcnt2 + 1 Loop End If End If Loop End Sub |