Reputation: 11
i'm facing issues while creating child directories within the Documents dir
i get Documents path with NSHomeDirectory() return: /var/mobile/Containers/Data/Application/3CE312DC-8A49-4EF6-83D1-C205F2EF1C0B
and create dir with
std::filesystem::create_directory((homePath+"/Documents/assets").c_str())
return success
std::filesystem::create_directory((homePath+"/Documents/assets/images").c_str())
return permission denied
and with NSFileManager return the same
void iOSCreateDirectory(const char*path){
NSString*directory=[NSString stringWithUTF8String:path];
NSError*err;
NSFileManager*fm=[NSFileManager defaultManager];
if(![fm fileExistsAtPath:directory]){
if(![fm createDirectoryAtPath:directory withIntermediateDirectories:YES attributes:nil error:&err]){
NSLog(@"CreateDirectory Error %@ %@", directory, err);
}
}
}
iOSCreateDirectory((homePath+"/Documents/assets").c_str())
return success
iOSCreateDirectory((homePath+"/Documents/assets/images").c_str())
return Code=13 "permission denied"
Error Code=513 "You don't have permission to save the file "images" in the folder "assets"."
am i missing something here?
Solved
the problem is the assets directory was created with std::filesystem::create_directory()
Thanks
Upvotes: 0
Views: 118
Reputation: 20376
I suspect it may be a formatting issue with your path construction. This works:
NSFileManager *fm = [NSFileManager defaultManager];
NSURL *appDirURL = [[fm URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
NSError *error;
NSURL *newDirectoryURL = [[appDirURL URLByAppendingPathComponent:@"assets"] URLByAppendingPathComponent:@"images"];
if (![fm createDirectoryAtURL:newDirectoryURL withIntermediateDirectories:YES attributes:nil error:&error]) {
NSLog(@"Error: %@", [error localizedDescription]);
}
Upvotes: 0