2014-09-03 206 views
-2
Files = Directory.GetFiles(localFilename, "*.html"); 

最終我得到了許多例子中的目錄文件中的第一個指標是:如何刪除所有目錄中的所有文件?

C:\測試\測試\ test.html的

第二個索引:

C:\測試\測試\ test1.html

我想只刪除文件:test.html中,test1.html等等...

+0

多數民衆贊成在一個常問的問題只是谷歌「刪除目錄C#遞歸文件」 – 2014-09-03 10:39:47

+0

爲什麼你會得到很多目錄? 'localFilename'是一個目錄名稱。您可以使用[this overload](http://msdn.microsoft.com/zh-cn/library/ms143316(v = vs.110).aspx)tio指定'SearchOption.AllDirectories'。但答案保持不變,因爲GetFiles不僅返回文件名,而且返回完整路徑。 – 2014-09-03 10:39:48

回答

2
foreach(var file in Files) 
    File.Delete(file); 
相關問題