|
-
Feb 11th, 2003, 04:06 PM
#1
Thread Starter
Addicted Member
Including subdirectories?
I have this code:
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' make a reference to a directory
Dim di As New IO.DirectoryInfo("c:\")
Dim diar1 As IO.FileInfo() = di.GetFiles()
Dim dra As IO.FileInfo
'list the names of all files in the specified directory
For Each dra In diar1
ListBox1.Items.Add(dra)
Next
End Sub
How do I make it so that it includs subdirectories?
-
Feb 11th, 2003, 08:55 PM
#2
PowerPoster
Your going to have to use recursion to implement what you want.
Basically, you are going to want to create a seperate Function that calls itself for each subdirectory until there is no subdirectories left. Then that function will start returning the files to the calling function (which will be itself most of the time).
-
Feb 11th, 2003, 11:19 PM
#3
Thread Starter
Addicted Member
So there is no easy way to do it like includeSubdirectories = True?
-
Feb 12th, 2003, 08:36 AM
#4
PowerPoster
Not that I know of...maybe someone else knows. The code isn't that hard to do. When I get home I will try to remember to whip something up for you if you need it.
-
Feb 12th, 2003, 11:13 AM
#5
PowerPoster
This gets all the sub folders, you can easily modify it to work for files if you want. At least this can help get you started.
VB Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
ListBox1.Items.Clear()
ProcessFolder("c:\inetpub\")
End Sub
Private Sub ProcessFolder(ByVal Path As String)
Dim objDI As New System.IO.DirectoryInfo(Path)
Dim objFolders As System.IO.DirectoryInfo()
Dim objFolder As System.IO.DirectoryInfo
objFolders = objDI.GetDirectories
For Each objFolder In objFolders
Debug.WriteLine(objFolder.FullName)
ListBox1.Items.Add(objFolder.FullName)
ProcessFolder(objFolder.FullName)
Next
End Sub
-
Feb 12th, 2003, 11:26 AM
#6
Thread Starter
Addicted Member
I did actuly get my program to search in the subdirectories, but thanks for the code.
I'm suprised that you can't do this very easly, when I was programming in vba 6.0 it was really easy;
all you had to do was something like this:
application.filesearch.includesubdirectories = true
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
|