当前位置: 编程技术>.net/c#/asp.net
c# 删除空文件夹的代码
来源: 互联网 发布时间:2014-08-30
本文导语: 删除空文件夹的代码。 代码示例: /// /// 删除掉空文件夹 /// /// public static void KillEmptyDirectory(String storagepath) { DirectoryInfo dir = new DirectoryInfo(storagepath); DirectoryInfo[] subdirs = dir.GetDirectories("*.*", SearchOption.AllDirectories); foreac...
删除空文件夹的代码。
代码示例:
///
/// 删除掉空文件夹
///
///
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();
}
}
}
/// 删除掉空文件夹
///
///
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();
}
}
}