using System;

using System.IO;

 

namespace ex060709_file

{

       class C

       {

              public void TranverseDir(string path, int n, StreamWriter sw)

              {

 

                     try

                     {

                            DirectoryInfo  di = new DirectoryInfo(path);

                            if(!di.Exists)

                                   return;

                            DirectoryInfo[] dis= di.GetDirectories();

                            for(int i=0; i<dis.Length; i++)

                            {

                                   for(int j=0; j<n;j++)

                                          sw.Write(" ");

                                   sw.WriteLine(dis[i].FullName);

                                   this.TranverseDir(dis[i].FullName, n+5, sw);

                            }

                            FileInfo[]  fis = di.GetFiles();

                            for(int i=0; i<fis.Length;i++)

                            {

                                   for(int j=0; j<n;j++)

                                          sw.Write(" ");

                                   sw.WriteLine(fis[i].Name);

                            }

                     }

                     catch

                     {}

              }

      

       }

       class Test

       {

              static void Main()

              {

 

                     C c = new C();

                     StreamWriter sw = new StreamWriter(@"c:\q.qq");

                     string s = @"c:\";

            sw.WriteLine(s);

                     c.TranverseDir(s, 5, sw);

                     sw.Close();

              }

       }

}

posted on 2008-11-12 23:59  〆o殺殸纨o〆  阅读(119)  评论(0编辑  收藏  举报