Tôi đã tạo ra một số thư mục trong NSDocumentDirectory nhưLàm thế nào để có được danh sách các giám đốc trong NSDocumentDirectory?
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?");
}
}
}
Bây giờ tôi muốn có được danh sách các thư mục mà tôi đã tạo ra trong thư mục tài liệu nhưng phản ứng là
NSArray *arrPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *basePathString = ([arrPaths count] > 0) ? [arrPaths objectAtIndex:0] : nil;
NSLog(@"dirContents %@",basePathString);
đáp ứng là :
/Users/amir/Library/Application Support/iPhone Simulator/6.1/Applications/7003E8D5-CCBB-4E54-896B-F4BD2F4D2CB1/Documents
phản hồi trong tất cả các tệp. nhưng tôi chỉ muốn lấy tên của các thư mục. –
@AmiriDev tôi đã cập nhật mã. – SAPLogix