- (NSURL *) applicationDocumentsDirectory
{
return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
}
….
NSURL *folder = [[[Database sharedInstance] applicationDocumentsDirectory] URLByAppendingPathComponent:@"temp"];
BOOL isFolder;
NSLog(@"URL: %@", folder);
if ([[NSFileManager defaultManager] fileExistsAtPath:folder.absoluteString isDirectory:&isFolder] == NO)
{
NSLog(@"IsFolder: %d", isFolder);
[[NSFileManager defaultManager] createDirectoryAtURL:folder withIntermediateDirectories:YES attributes:nil error:&error];
if (error)
NSLog(@"Error: %@", error.localizedDescription);
}
I run this part of code twice.
I expect that the folder will be created, but every time I receive a log: “IsFolder: 7”.
Why the folder wasn’t created after the first run?
Please, replace folder.absoluteString to folder, your problem will be solved.
Follow step by step:
1) Get documents folder
2) Get documents folder and folder name
3) Check alerdy exists or not