代碼如下:
/// <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();
}
}
}