Come elencare tutte le sottodirectory di una data directory
La routine fa uso della funzione accessoria IsAttr
N.B. La lista delle directory viene visualizzata nella finestra di Debug
Codice VB per elencare le sottodirectory di una directory:
Option Explicit
Private Sub Command1_Click()
Call ListSubDirs("C:\Programmi")
End Sub
Sub ListSubDirs(strPath As String)
Dim strFile As String
If Right(strPath, 1) <> "\" Then strPath = strPath & "\"
If IsAttr(strPath, vbDirectory) Then
strFile = Dir(strPath, vbDirectory)
Do Until strFile = ""
If IsAttr(strPath & strFile, vbDirectory) Then
If strFile <> "." And strFile <> ".." Then
Debug.Print strFile
End If
End If
strFile = Dir
Loop
End If
End Sub
Function IsAttr(strFile As String, lngAttr As Long) As Boolean
On Error Resume Next
IsAttr = ((GetAttr(strFile) And lngAttr) = lngAttr)
End Function
Testato su: tutti i Sistemi Operativi