ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfSystemIODirectoryClassGetFilesTo
pic.htm
From the VS.Net 2002 MSDN install. Should be able to find it at MSDN as
well.
' For Directory.GetFiles and Directory.GetDirectories
' For File.Exists, Directory.Exists
Imports System
Imports System.IO
Imports System.Collections
' Takes an array of file names or directory names on the command line.
' Determines what kind of name it is and processes it appropriately
Public Class RecursiveFileProcessor
'Entry point which delegates to C-style main function
Public Overloads Shared Sub Main()
Main(System.Environment.GetCommandLineArgs())
End Sub
Overloads Public Shared Sub Main(args() As String)
Dim path As String
For Each path In args
If File.Exists(path) Then
' This path is a file
ProcessFile(path)
Else
If Directory.Exists(path) Then
' This path is a directory
ProcessDirectory(path)
Else
Console.WriteLine("{0} is not a valid file or
directory.", path)
End If
End If
Next path
End Sub 'Main
' Process all files in the directory passed in, and recurse on any
directories
' that are found to process the files they contain
Public Shared Sub ProcessDirectory(targetDirectory As String)
Dim fileEntries As String() = Directory.GetFiles(targetDirectory)
' Process the list of files found in the directory
Dim fileName As String
For Each fileName In fileEntries
ProcessFile(fileName)
Next fileName
Dim subdirectoryEntries As String() =
Directory.GetDirectories(targetDirectory)
' Recurse into subdirectories of this directory
Dim subdirectory As String
For Each subdirectory In subdirectoryEntries
ProcessDirectory(subdirectory)
Next subdirectory
End Sub 'ProcessDirectory
' Real logic for processing found files would go here.
Public Shared Sub ProcessFile(path As String)
Console.WriteLine("Processed file '{0}'.", path)
End Sub 'ProcessFile
End Class 'RecursiveFileProcessor
"Elmo Watson" <sp**********@nospamYahoo.com> wrote in message
news:OQ**************@tk2msftngp13.phx.gbl...
I found what I have in MSDN - - I have not been able, even after your
message, of finding the example - - - are you saying MSDN Online? (got a
link?)
"Morgan" <mf****@spamcop.net> wrote in message
news:ed**************@TK2MSFTNGP10.phx.gbl... There is a sample in the MSDN help that does -exactly- what you are
looking to do.
Essentially you have to create a recursive procedure and iterate through
the directories.
<Psuedo code>
Private Sub GetDir(DirName as string)
For each directory in directoryInfo.GetDirectories(DirName)
GetDir(directory.name)
Next
End Sub
"Elmo Watson" <sp**********@nospamYahoo.com> wrote in message
news:OX**************@TK2MSFTNGP12.phx.gbl...
Is there a way, with the System.IO class, to do a recursive list of a
directory structure?
For instance, in DirectoryInfo, you have GetDirectories and GetFiles ....
In Directory, you have Directory.GetFileSystemEntries(path), but I
would like to know how to put this together, knowing which entry is a
Subdirectory and which entry is a file, and make a recursive list of the Directory
structure below a specific path - - -
For instance, I have:
Dim str As String
For Each str In directoryEntries
response.write (str & "<br>")
' here, I'd like to figure out whether it's a subdirectory or a
file - - if it's a subdirectory, go into it and list it's files and
subdirectories - - - - total recursiveness is what I'm after and it's
got me loony.
Next Str
Any ideas?