c# 删除所有的空文件夹

http://www.amazon.cn/Lvze-sp-%E7%BB%BF%E6%B3%BD%E5%B0%9A%E5%93%81-%E6%97%85%E8%A1%8C%E7%AE%B1-%E6%8B%89%E6%9D%86%E7%AE%B1-%E7%99%BB%E6%9C%BA%E7%AE%B1-%E6%8B%89%E6%9D%86%E5%8C%85%E4%B8%AD%E6%80%A7-%E9%AB%98%E6%A1%A3%E5%95%86%E5%8A%A1%E4%BC%91%E9%97%B2%E5%8C%85-20%E5%AF%B8%E9%9D%99%E9%9F%B3%E4%B8%87%E5%90%91%E8%BD%AE-%E6%8B%89%E6%9D%86%E8%83%8C%E5%8C%85628/dp/B00A1YD0TS/ref=sr_1_9?ie=UTF8&qid=1363954751&sr=8-9

///
<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(); } } }

 

你可能感兴趣的:(文件夹)