一個根文件夾
如果要刪除所有子文件又保存最頂級的目錄文件夾
處理方法
void deleteAllFile(string path)
{
Directory
Directory
}
///
/// 遍歷文件夾及子文件夾所有文件
///
///
///
文件夾目錄路徑
///
public static System
{
ArrayList arylist = null;
if (Directory
{
DirectoryInfo dinfo = new DirectoryInfo(fileDirectory);
if (dinfo != null)
{
FileSystemInfo[] files = dinfo
for (int i =
{
FileInfo file = files[i] as FileInfo;
if (file != null)
{
if (arylist == null)
arylist = new ArrayList();
arylist
}
else
{
ListFiles(files[i]
}
}
}
}
return arylist;
}
用第一個方法最直接
總體來說應該是第一種方法比第二種方法的性能要好!待進一步求證
刪除一個文件夾下所有文件可以用如下文件方法
void deleteAllFile(string path)
{
foreach (string dirStr in Directory
{
DirectoryInfo dir = new DirectoryInfo(dirStr);
}
ArrayList folders=new ArrayList();
FileSystemInfo[] fileArr = dir
for (int i =
{
FileInfo f = folders[i] as FileInfo;
if (f == null)
{
DirectoryInfo d = folders[i] as DirectoryInfo;
d
}
}
}
From:http://tw.wingwit.com/Article/program/net/201311/14200.html