删除空文件夹的代码。
复制代码 代码示例:
/// <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();
}
}
}