c# 删除所有的空文件夹的小例子

复制代码 代码如下:

///
        /// 删除掉空文件夹
        /// 所有没有子“文件系统”的都将被删除
        ///

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

你可能感兴趣的:(c# 删除所有的空文件夹的小例子)