|
-
Apr 7th, 2008, 08:23 PM
#1
Thread Starter
Lively Member
[Resolved][2008]searching subfolders
Well looks like 99% of the codes I found in the help file & in this forum are broken, they simply arent working. I get errors like file type not defined, or not declared.
I know this is simple, but i just cant figure out how can i make it search further than 1 sub folder. I heard that this should be done recrusively, but I dont really understand how that thing works. Mayb someone can help me out hire?
This is my code so far, that works it cant search Drives tho..
Code:
Dim startdir = "C:\New Folder\"
For Each listfolders As String In My.Computer.FileSystem.GetDirectories(startdir)
Me.ListBox1.Items.Add(listfolders)
For Each listfiles As String In My.Computer.FileSystem.GetFiles(listfolders)
Me.ListBox1.Items.Add(listfiles)
Next
Next
Last edited by goldenix; Apr 8th, 2008 at 05:35 PM.

M.V.B. 2008 Express Edition
-
Apr 7th, 2008, 08:35 PM
#2
Frenzied Member
Re: [2008]searching subfolders
Code:
Dim sGetFiles() As String = IO.Directory.GetFiles("PATH", "*.*", SearchOption.AllDirectories)
That retrieves all files the "*.*" part from, PATH, and searches all sub directories.. for files as well..
Cheers
-
Apr 7th, 2008, 08:42 PM
#3
Thread Starter
Lively Member
Re: [2008]searching subfolders
 Originally Posted by Icyculyr
That retrieves all files the "*.*" part from, PATH, and searches all sub directories.. for files as well..
Cheers
this is strange Im getting: 'SearchOption' is not declared. error

M.V.B. 2008 Express Edition
-
Apr 7th, 2008, 09:16 PM
#4
Re: [2008]searching subfolders
If you haven't imported the System.IO namespace then it would be IO.SearchOption.AllDirectories.
Just keep in mind that if such a search encounters an inaccessible folder it will fail and throw an exception. For that reason you cannot search your entire C; drive that way as it will always fail. If you might be searching a folder tree with inaccessible folders then you need to write your own recursive file search. It's dead easy using Directory.GetFiles and Directory.GetDirectories and there would be more than one example on the forums already.
-
Apr 8th, 2008, 05:43 PM
#5
Thread Starter
Lively Member
Re: [Resolved][2008]searching subfolders
Thanx both of you.
Hire is the code if someone has the same question
Code:
Dim file = "C:\New Folder"
Dim sGetFiles() As String = IO.Directory.GetFiles(file, "*.*", IO.SearchOption.AllDirectories)
For ii = 0 To sGetFiles.GetUpperBound(0)
MsgBox(IO.Path.GetFileName(sGetFiles(ii)))
Next

M.V.B. 2008 Express Edition
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
|