Create a directory on the iPhone

I want to know how to create a directory at the specified path. I used "system (" directory path "); this works fine in the simulator, but not on the device

+4
source share
2 answers

To create a new directory in the directory of your application library, use this ...

// Generate the path to the new directory NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES); NSString *newDirectory = [NSString stringWithFormat:@"%@/new", [paths objectAtIndex:0]]; // Check if the directory already exists if (![[NSFileManager defaultManager] fileExistsAtPath:newDirectory]) { // Directory does not exist so create it [[NSFileManager defaultManager] createDirectoryAtPath:newDirectory withIntermediateDirectories:YES attributes:nil error:nil]; } 
+8
source

createDirectoryAtPath:attributes: method deprecated.

Use createDirectoryAtPath:withIntermediateDirectories:attributes:error: instead.

+2
source

All Articles