create a directory in the iPhone
17,101
Solution 1
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];
Solution 2
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");
Related videos on Youtube
Author by
Mathieu
Updated on June 04, 2022Comments
-
Mathieu almost 2 years
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");