VB.Net Recursive Dir/File
VB.Net Recursive Dir/File
VB.Net Recursive Dir/File
VB.Net Recursive Dir/File
VB.Net Recursive Dir/File
VB.Net Recursive Dir/File VB.Net Recursive Dir/File VB.Net Recursive Dir/File VB.Net Recursive Dir/File VB.Net Recursive Dir/File VB.Net Recursive Dir/File VB.Net Recursive Dir/File VB.Net Recursive Dir/File
VB.Net Recursive Dir/File VB.Net Recursive Dir/File
VB.Net Recursive Dir/File
Go Back  Xtreme Visual Basic Talk > > > > VB.Net Recursive Dir/File


Reply
 
Thread Tools Display Modes
  #1  
Old 04-03-2004, 03:42 PM
excaliber's Avatar
excaliberVB.Net Recursive Dir/File excaliber is offline
Senior Contributor

* Expert *
 
Join Date: Nov 2002
Location: Ohio, USA
Posts: 1,828
Default VB.Net Recursive Dir/File


Thought I'd share this snippet of code. It recursively goes through every subdirectory under the main directory, listing both subdir's and files.

It's overloaded. Call the first one by providing only the target path. It uses the second overloaded function for the recursive part. The code is fairly self-explanatory.

Code:
Private [COLOR=Blue]Overloads[/COLOR] Function Recursive(ByVal strPath As String) Dim oDir As New System.IO.DirectoryInfo(strPath) Dim oSubDir() As System.IO.DirectoryInfo Dim oFiles() As System.IO.FileInfo Dim i As Int32 oFiles = oDir.GetFiles For i = 0 To oFiles.Length - 1 Debug.WriteLine(oFiles(i).Name.ToString) Next oSubDir = oDir.GetDirectories() For i = 0 To oSubDir.Length - 1 Debug.WriteLine(oSubDir(i).Name.ToString) 'more code to do whatever here Call Recursive(oSubDir(i), 1) Next End Function Private [COLOR=Blue]Overloads[/COLOR] Function Recursive(ByVal oDir As System.IO.DirectoryInfo, ByVal intLevel As Int32) Dim oSubDir() As System.IO.DirectoryInfo Dim oFiles() As System.IO.FileInfo Dim i As Int32 oFiles = oDir.GetFiles For i = 0 To oFiles.Length - 1 Debug.WriteLine(New String(" ", intLevel) & ">" & oFiles(i).Name.ToString) Next oSubDir = oDir.GetDirectories() For i = 0 To oSubDir.Length - 1 Debug.WriteLine(New String(" ", intLevel) & oSubDir(i).Name.ToString) 'more code to do whatever here Call Recursive(oSubDir(i), intLevel + 1) Next End Function
__________________
RandomIRC - Your neighborhood's friendly IRC channel (irc.randomirc.com - #code)

"Perl - The only language that looks the same before and after RSA encryption."

Last edited by Iceplug; 04-06-2004 at 02:42 PM. Reason: Colorized for VB.NET
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing variables and controls using WinForms and VB.NET Bucky Tutors' Corner 0 02-24-2004 04:45 PM
VB6 vs VB.NET geo1st487 Tech Discussions 10 01-31-2004 10:37 PM
Open VB.NET 2002 project within VB.NET 2003 geo1st487 .NET General 2 01-10-2004 05:13 PM
VB.Net Office Integration FAQ Mike Rosenblum .NET Office Automation 2 12-19-2003 01:17 PM
A VB6 to VB.NET conversion sample Helmar General 0 11-14-2001 06:27 PM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
VB.Net Recursive Dir/File
VB.Net Recursive Dir/File
VB.Net Recursive Dir/File VB.Net Recursive Dir/File
VB.Net Recursive Dir/File
VB.Net Recursive Dir/File
VB.Net Recursive Dir/File VB.Net Recursive Dir/File VB.Net Recursive Dir/File VB.Net Recursive Dir/File VB.Net Recursive Dir/File VB.Net Recursive Dir/File VB.Net Recursive Dir/File
VB.Net Recursive Dir/File
VB.Net Recursive Dir/File
 
VB.Net Recursive Dir/File
VB.Net Recursive Dir/File
 
-->