Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Working with system folders

Status
Not open for further replies.

barrykellett

Programmer
Mar 4, 2003
29
GB
I need to produce some sample code which will produce a list of folders and sub folders and the files in these folders.
Would anyone have a sample piece of code that would do this?
I have been searching for a long long time on the web without much success for this.
 
The below code is untested and has been adapted from the documentation on MSDN


Code:
public static void ProcessDirectory(string targetDirectory) {
        // Process the list of files found in the directory
        string [] fileEntries = Directory.GetFiles(targetDirectory);
        foreach(string fileName in fileEntries)
           Response.Write(targetDirectory + "/" + fileName);

        // Recurse into subdirectories of this directory
        string [] subdirectoryEntries = Directory.GetDirectories(targetDirectory);
      foreach(string subdirectory in subdirectoryEntries)
          ProcessDirectory(subdirectory);
}
It should do what your looking for.

Rob

Go placidly amidst the noise and haste, and remember what peace there may be in silence - Erhmann 1927
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top