Recurse thru sub directories
I haven't seen this on PSC using the filesystem object or a collection. very neat and fast since you don't need to go through it twice to redim an array. the only slow down with this code is the print statement.
AI
ИИ-обзор: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
Исходный код
Private Sub Command1_Click()
Dim lForIndex As Long
Set colDirs = Nothing
Set colDirs = New Collection
Me.List1.Clear
DoEvents
colToFill.Add Item:=endInSlash("C:")
Call makeTree("C:", colDirs)
For lForIndex = 1 To colDirs.Count
Debug.Print colDirs.Item(lForIndex)
Next lForIndex
End Sub
Sub makeTree(ByVal inPath As String, ByRef colToFill As Collection)
Dim objDir1 As Folder
Dim objDir2 As Folder
Dim sCurrentDir As String
sCurrentDir = endInSlash(inPath)
Set objDir1 = objFso.GetFolder(sCurrentDir)
For Each objDir2 In objDir1.SubFolders
colToFill.Add Item:=sCurrentDir & objDir2.Name
Call makeTree(sCurrentDir & objDir2.Name, colToFill)
Next objDir2
Set objDir1 = Nothing
Set objDir2 = Nothing
End Sub
Function endInSlash(ByVal inString As String) As String
If Right$(inString, 1) <> "\" Then
endInSlash = inString & "\"
Else
endInSlash = inString
End If
End Function
Оригинальные комментарии (3)
Восстановлено из Wayback Machine