create a directory in the iPhone
-
20-09-2019 - |
Question
What's wrong with that?
#define AUDIO_NOTES_FOLDER [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/myApp/Pictures"]
NSFileManager *NSFm= [NSFileManager defaultManager];
BOOL isDir=YES;
if(![NSFm fileExistsAtPath:FILEPATH isDirectory:&isDir])
if(![NSFm createDirectoryAtPath:FILEPATH attributes:nil])
NSLog(@"Error: Create folder failed");
Solution
The FILEPATH token is undefined - you #define AUDIO_NOTES_FOLDER
at the beginning of your file, then use FILEPATH
instead in your code.
Also note that NSHomeDirectory() isn't necessarily the recommended way of finding the Documents directory anymore - instead you probably want:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
OTHER TIPS
createDirectoryAtPath:attributes:
is deprecated, instead you should use:
NSString *dirToCreate = [NSString stringWithFormat:@"%@/newDirectory",[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]];
NSError *error = nil;
BOOL isDir;
if(![fm fileExistsAtPath:dirToCreate isDirectory:&isDir])
if(![fm createDirectoryAtPath:dirToCreate withIntermediateDirectories:YES attributes:nil error:&error])
NSLog(@"Error: Create folder failed");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow