Recursive Directory use : Directory : File Directory Stream C# Examples


C# Examples » File Directory Stream » Directory »

 

Recursive Directory use









    
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);
    }
}
    
   
  
   



Output

c:\
  b
  Documents and Settings
    All Users
      Application Data
        Adobe
          Acrobat
            6.0
              Replicate
                Security
        Microsoft
          CoreCon
^CTerminate batch job (Y/N)? n


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo File Directory Stream
» Directory