|
-
Jan 6th, 2004, 01:07 PM
#1
Thread Starter
Frenzied Member
directories
How can I iterate through all folders and its subfolders within a given directory.
Ex.
Say that I get c:\demo
I want to find all subfolders within that folder and all subsequent ones.
c:\demo\sub1\sub2\sub3\sub4 etc...
Thanks,
Don't anthropomorphize computers -- they hate it
-
Jan 6th, 2004, 01:28 PM
#2
I'm too lazy to tell how to do it, so I give the code right away And I'm too lazy to edit the file getting part out of it... but I'm sure you can modify it to store all the directories.
VB Code:
Dim DirList As New Collection, FileList As New Collection, Temp As String
On Error Resume Next
DirList.Add "C:\"
Do While DirList.Count
Temp = Dir$(DirList(1), vbDirectory)
Do Until Temp = ""
If Temp = "." Or Temp = ".." Then
'do nothing
ElseIf (GetAttr(FixPathFile(DirList(1), Temp)) And vbDirectory) = vbDirectory Then
DirList.Add FixPathFile(DirList(1), Temp) & "\"
Else
FileList.Add FixPathFile(DirList(1), Temp)
End If
Temp = Dir
Loop
DirList.Remove 1
Loop
'now FileList contains all files
VB Code:
'in a module
Public Function FixPathFile(ByVal Path As String, File As String) As String
If Right$(Path, 1) <> "\" Then Path = Path & "\"
FixPathFile = Path & File
End Function
-
Jan 6th, 2004, 01:57 PM
#3
Thread Starter
Frenzied Member
This does not return anything.
Don't anthropomorphize computers -- they hate it
-
Jan 6th, 2004, 02:21 PM
#4
Spend time reading the code, don't just go ahead and paste. If you read the comment, you'd understand FileList contains a list of all files found in the directories. Now, it shouldn't be a big job to rip this functionality out and add functionality to add found directories to a listbox, for example.
-
Jan 6th, 2004, 02:36 PM
#5
Fanatic Member
That's a cool way to do it!! I used to use a recursive function before - not anymore!!!
-
Jan 6th, 2004, 11:34 PM
#6
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|