本文實(shí)例講述了asp.net編程實(shí)現(xiàn)刪除文件夾及文件夾下文件的方法。分享給大家供大家參考,具體如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
//獲取文件夾 string path = Server.MapPath( "Image" ); //獲取文件夾中所有圖片 if (Directory.GetFileSystemEntries(path).Length > 0) { //遍歷文件夾中所有文件 foreach ( string file in Directory.GetFiles(path)) { //文件己存在 if (File.Exists(file)) { FileInfo fi = new FileInfo(file); //判斷當(dāng)前文件屬性是否是只讀 if (fi.Attributes.ToString().IndexOf( "ReadyOnly" ) >= 0) { fi.Attributes = FileAttributes.Normal; } //刪除文件 File.Delete(file); } } //刪除文件夾 Directory.Delete(path); } |
希望本文所述對(duì)大家asp.net程序設(shè)計(jì)有所幫助。