c# 刪除一個資料夾下的所有空資料夾
阿新 • • 發佈:2018-11-29
/// <summary>
/// 刪除掉空資料夾
/// 所有沒有子“檔案系統”的都將被刪除
/// </summary>
/// <param name="storagepath"></param>
public static void KillEmptyDirectory(String storagepath)
{
DirectoryInfo dir = new DirectoryInfo(storagepath);
DirectoryInfo[] subdirs = dir.GetDirectories("*.*", SearchOption.AllDirectories);
foreach (DirectoryInfo subdir in subdirs)
{
FileSystemInfo[] subFiles = subdir.GetFileSystemInfos();
if (subFiles.Count() == 0)
{
subdir.Delete();
}
}
}