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

时间:2021-12-04 12:27:08
// 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]);
  }
}