//清空附件文件夹内文件
string dir = AppDomain.CurrentDomain.BaseDirectory + "\\files";
if (System.IO.Directory.Exists(dir))
{
EUtil.DeleteFolderFiles(dir);
}
else
{
System.IO.Directory.CreateDirectory(dir);
}
/// <summary>
/// 清空文件夹内所有文件(保留文件夹)
/// </summary>
/// <param name="dir"></param>
public static void DeleteFolderFiles(string dir)
{
try
{
DirectoryInfo d = new DirectoryInfo(dir);
FileSystemInfo[] fileinfo = d.GetFileSystemInfos();
foreach (FileSystemInfo i in fileinfo)
{
if (i is DirectoryInfo)
{
DirectoryInfo subdir = new DirectoryInfo(i.FullName);
subdir.Delete(true);
}
else
{
File.Delete(i.FullName);
}
}
}
catch (Exception )
{
throw;
}
}