当前位置: 编程技术>.net/c#/asp.net
如何清空文件夹里面的所有文件和文件夹
来源: 互联网 发布时间:2014-10-22
本文导语: 代码如下:private void deletefileOrDic(System.IO.DirectoryInfo path) { try { foreach (System.IO.DirectoryInfo d in path.GetDirectories()) { ...
代码如下:
private void deletefileOrDic(System.IO.DirectoryInfo path)
{
try
{
foreach (System.IO.DirectoryInfo d in path.GetDirectories())
{
d.Delete(true);
}
foreach (System.IO.FileInfo f in path.GetFiles())
{
f.Delete();
}
}
catch (Exception ex)
{
}
}