.Net System.IO 獲取資料夾下所有子資料夾名及目錄
阿新 • • 發佈:2021-01-26
.Net System.IO 獲取資料夾下所有子資料夾名及目錄
//獲取path下所有的資料夾
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(path);
System.IO.DirectoryInfo[] folders = dir.GetDirectories();
//獲取資料夾名
string[] folderName = new string[folders.Length];
string [] folderPath = new string[folders.Length];
int leng = 0;
foreach (System.IO.DirectoryInfo item in folders)
{
//獲取資料夾名
folderName[leng] = item.Name;
//獲取子目錄路徑
folderPath[leng] = path + @"\" + item.Name;
leng++;
}