Search code examples
iphoneobjective-cfilesystemsnsfilemanager

create a directory in the 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");

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];