我已經獲取文檔目錄的路徑並在裏面創建一些目錄。我已經知道如何檢查目錄是否存在,刪除它或其文件,但是,我如何列出目錄?謝謝。iOS列表現有目錄
的文件列表,我用:
int Count;
NSString *path;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
path = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"SomeDirectoryName"];
NSArray *directoryContent = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:NULL];
for (Count = 0; Count < (int)[directoryContent count]; Count++)
{
NSLog(@"File %d: %@", (Count + 1), [directoryContent objectAtIndex:Count]);
}
你能指導我該怎麼做嗎? – 2013-02-18 07:00:34
@AmiriDev你看看[-enumeratorAtPath:']的文檔(https://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSFileManager_Class/Reference/Reference.html %23 // apple_ref/OCC/instm /的NSFileManager/enumeratorAtPath :)?這裏有一個例子。 – Caleb 2013-02-18 07:12:47
你能回答這個問題嗎? http://stackoverflow.com/questions/14931224/how-to-get-the-list-of-directores-in-nsdocumentdirectory – 2013-02-18 07:21:48