C# 删除文件目录下所有文件
作者:互联网
public static void DelectDir(string srcPath)
{
try
{
DirectoryInfo dir = new DirectoryInfo(srcPath);
FileSystemInfo[] fileinfo = dir.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 e)
{
throw;
}
}
标签:文件,文件目录,删除,C#,FileSystemInfo,DirectoryInfo,srcPath,new,fileinfo 来源: https://www.cnblogs.com/nuomibaibai/p/16647461.html