Recursive Directory use : Directory « File Directory Stream « C# / CSharp Tutorial






using System;
using System.IO;

class MainClass
{
  public static void ShowDirectory(DirectoryInfo di, int intLevel) 
  {
    string strPad = new String(' ', 2*intLevel);
    Console.WriteLine(strPad + di.Name);

    foreach (DirectoryInfo diChild in di.GetDirectories())
      ShowDirectory(diChild, intLevel+1);
  }

  public static void Main() 
  {
    DirectoryInfo di = new DirectoryInfo("c:\\");
    ShowDirectory(di, 0);
  }
}
c:\
  b
  Documents and Settings
    All Users
      Application Data
        Adobe
          Acrobat
            6.0
              Replicate
                Security
        Microsoft
          CoreCon
^CTerminate batch job (Y/N)? n








15.15.Directory
15.15.1.Get the files from the root directory
15.15.2.Use file filer on a directory
15.15.3.Directory.Exists
15.15.4.Get Current Directory
15.15.5.Get relative path
15.15.6.Changing current directory to c:\\
15.15.7.Delete Directory
15.15.8.Directory Attributes
15.15.9.Use DirectoryInfo to create sub directory
15.15.10.List directory under a directory
15.15.11.List files under a directory
15.15.12.All Directories traverses all sub-directories under the root
15.15.13.Traverse all files under the root
15.15.14.Recursive Directory use
15.15.15.Get DirectoryInfo from FileInfo: name, parent directory name, directory exists
15.15.16.DirectoryInfo: creation time, last write time, last access time
15.15.17.DirectoryInfo: Directory attribute list and Directory contains
15.15.18.Using Directory type
15.15.19.Recursely Explore Directories
15.15.20.Show basic directory info
15.15.21.Modify directory structure
15.15.22.Creating Subdirectory and Manipulating File
15.15.23.Exploring Files And Sub directories
15.15.24.Create directory structure
15.15.25.Get all cs file from current directory, display its creation time, length, name
15.15.26.Use the GetFiles method to return file names from a user-specified location.