2012-02-20 36 views

回答

2

簡單,

FOLDERPATH是你的文件目錄的路徑。

NSString *folderPath; 

NSArray *dirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:folderPath error:&error]; 
     for (NSString *strName in dirContents) {       
       [[NSFileManager defaultManager] removeItemAtPath:[folderPath stringByAppendingPathComponent:strName] error:&error];  
     } 

希望這將有助於你

+2

不要忘記檢查removeItemAtPath:嘗試使用錯誤對象之前實際失敗。至少,你可能會報告比實際情況更多的錯誤。 NSError * err = nil; BOOL res; res = [[NSFileManager defaultManager] removeItemAtPath:[folderPath stringByAppendingPathComponent:strName] error:&error];如果(!res && error){ NSLog(@「oops:%@」,error); } – iosfanboy9 2012-02-20 10:19:26

相關問題