實現:
①
var files = Directory.GetFiles(@"C:\", "*.*",SearchOption.AllDirectories); // 遍歷所有檔案 var dirs= Directory.GetDirectories(@"C:\", "*", SearchOption.AllDirectories); //遍歷所有資料夾
②
var files = Directory.EnumerateFiles(@"C:\", "*.*",SearchOption.AllDirectories); // 遍歷所有檔案 var dirs= Directory.EnumerateDirectories(@"C:\", "*", SearchOption.AllDirectories); //遍歷所有資料夾 、 ③
var files = new DirectoryInfo(@"C:").GetFiles(".",SearchOption.AllDirectories); // 遍歷所有檔案,得到FileInfo型別的集合
var dirs= new DirectoryInfo(@"C:").GetDirectories("*", SearchOption.AllDirectories); //遍歷所有資料夾,得到DirectoryInfo型別的集合
var files = new DirectoryInfo(@"C:").EnumerateFiles(".",SearchOption.AllDirectories); // 遍歷所有檔案,得到FileInfo型別的集合
var dirs= new DirectoryInfo(@"C:").EnumerateDirectories("*", SearchOption.AllDirectories); //遍歷所有資料夾,得到DirectoryInfo型別的集合
`