Recursive File and Folder Listing VB.NET
Sep 12th, 2005 by jbloom
If you’re looking for a recursive file listing here’s some code for you.
Private Function RecursiveSearch(path as String) as Boolean Dim dirInfo As New IO.DirectoryInfo(path) Dim fileObject as FileSystemInfo for each fileObject in dirInfo.GetFileSystemInfos() If fileObject.Attributes = FileAttributes.Directory Then RecursiveSearch(fileObject.FullName) else Console.WriteLine(fileObject.FullName) End If next Return True End Function
Obviously there’s no error handling here so use this as a place to start.
Dude, this is awesome.. all other snipets are like 300 lines long.. you rock !!
great! don’t know how you did it, but it works
E, the trick (if there is one) here is that I examine each entry in a directory, if the entry is itself a directory, then I call the same function that I am in ‘RecursiveSearch’ with the new path of the directory.
When the new function instance has finished doing its work, the original running function continues wherever it left off.
That’s the point of recursion.
Very cool. I just have been using the brute force technique, like an idiot.
I will put a link to your site from mine after I make the code change, Thanks!
Simply elegant
Works in many languages, in c++ too.
I use this method in qt 3 by trolltech
……
}
}
else if ( fi->isDir() )
{
if ( fi->fileName() != “.” & fi->fileName() != “..” )
{
newDir = dir + fi->fileName () + “/”;
Update_dir( newDir, true );
…………