private void DelFile(string FilePath)
{
if (Directory.Exists(FilePath))
{
try
{
DirectoryInfo dir = new DirectoryInfo(FilePath);
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 ex)
{
MessageBox.Show(ex.ToString());
}
}
}