|
|
|
Thanks to the GetDirectories and GetFiles methods of the System.IO.Directory class, you need very little code to iterate over all the directories and files of a directory tree. For example, the following code snippet prints the structure of a directory tree and (optionally) the name of files in each directory: |
Click here to copy the following block |
Sub PrintDirTree(ByVal dir As String, ByVal showFiles As Boolean, _ Optional ByVal level As Integer = 0) Dim subdir As String Dim fname As String
Console.WriteLine(New String("-"c, level * 2) & dir)
Try If showFiles Then For Each fname In Directory.GetFiles(dir) Console.WriteLine(New String(" "c, level * 2 + 2) & fname) Next End If For Each subdir In Directory.GetDirectories(dir) PrintDirTree(subdir, showFiles, level + 1) Next Catch End Try End Sub
Dim rootDir As String For Each rootDir In Directory.GetLogicalDrives PrintDirTree(rootDir, True) Next |
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
|
|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|