我在NSDocumentDirectory創造了一些目錄,如何獲取NSDocumentDirectory中directores的列表?
if (![tbxCreateFolder.text isEqualToString:@""]) {
NSArray *arrPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectoryStr = [arrPaths objectAtIndex:0]; // Get documents folder
NSString *dataPath = [documentsDirectoryStr stringByAppendingPathComponent:[NSString stringWithFormat:@"/%@",tbxCreateFolder.text]];
if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath]){
NSError* error;
if([[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:&error]){
NSLog(@"success");
//Perfrom DB Insertation
}
else
{
NSLog(@"[%@] ERROR: attempting to write create MyFolder directory", [self class]);
NSAssert(FALSE, @"Failed to create directory maybe out of disk space?");
}
}
}
現在,我想我在文件夾創建的目錄列表,但反應
NSArray *arrPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *basePathString = ([arrPaths count] > 0) ? [arrPaths objectAtIndex:0] : nil;
NSLog(@"dirContents %@",basePathString);
反應是:
/Users/amir/Library/Application Support/iPhone Simulator/6.1/Applications/7003E8D5-CCBB-4E54-896B-F4BD2F4D2CB1/Documents
也在所有文件中響應。但我只想得到目錄的名稱。 – 2013-02-18 08:15:31
@AmiriDev我已經更新了代碼。 – SAPLogix 2013-02-18 08:28:39