Create directory in iPhone

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");

      

+2


source to share


2 answers


The FILEPATH icon is undefined - you #define AUDIO_NOTES_FOLDER

at the beginning of your file, then use it FILEPATH

instead in your code.

Also note that NSHomeDirectory () is not necessarily the recommended way to find the document directory - instead, you probably want:



NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
      

+11


source


createDirectoryAtPath:attributes:

deprecated, you should instead 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");

      

+13


source







All Articles