想要刪掉資料夾中所有的檔案,就要列出資料夾裡的檔案名稱 (List Contents of Directory)~
只要用這個method就可以輕易辦到囉~
-(NSArray *)listFileAtPath:(NSString *)path
{
//-----> LIST ALL FILES <-----//
NSLog(@"LISTING ALL FILES FOUND");
int count;
NSArray *directoryContent = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:NULL];
for (count = 0; count < (int)[directoryContent count]; count++)
{
NSLog(@"File %d: %@", (count + 1), [directoryContent objectAtIndex:count]);
}
return directoryContent;
}
執行結果:
LISTING ALL FILES FOUND
File 1: 1_FS2013-10-17_0.jpg
File 2: 1_FS2013-10-17_1.jpg
File 3: 1_FS2013-10-17_10.jpg
File 4: 1_FS2013-10-17_11.jpg
File 5: 1_FS2013-10-17_12.jpg
File 6: 1_FS2013-10-17_13.jpg
File 7: 1_FS2013-10-17_2.jpg
.
.
.
結果就是上圖中資料裡的內容囉!
參考:List saved files in iOS documents directory in a UITableView?。

Comments on: "[iOS] 列出資料夾裡的檔案名稱 (List Contents of Directory)" (1)
[…] 先前已寫過[iOS] 列出資料夾裡的檔案名稱 (List Contents of Directory),然而現在想要以最後修改時間列出檔案名稱 (List Contents of Directory By Last Modification Date),直接來看程式碼: […]
讚讚