C# 清空 文件夹

public static void ClearDirectory(string path)

{

if (Directory.Exists(path))

{

DirectoryInfo[] _di = new DirectoryInfo(path).GetDirectories();

for (int i = 0; i < _di.Length; i++)

{

ClearDirectory(_di[i].FullName);

Directory.Delete(_di[i].FullName);

}

FileInfo[] _files = new DirectoryInfo(path).GetFiles();

for (int i = 0; i < _files.Length; i++)

{

File.Delete(_files[i].FullName);

}

}

}

你可能感兴趣的:(C# 清空 文件夹)