C# 遍历指定目录下的所有文件及文件夹

// DirectoryInfo di = new DirectoryInfo(@"D:\Test");
// FindFile(di); 
static void FindFile(DirectoryInfo di)
{
  FileInfo[] fis = di.GetFiles();
  for (int i = 0; i < fis.Length; i++)
  {
    Console.WriteLine("文件:" + fis[i].FullName);
  }
  DirectoryInfo[] dis = di.GetDirectories();
  for (int j = 0; j < dis.Length; j++)
  {
    Console.WriteLine("目录:" + dis[j].FullName);
    FindFile(dis[j]);
  }
}

 

posted @ 2016-05-14 17:09  沙耶  阅读(7471)  评论(0编辑  收藏  举报