How to create a folder in the local iOS file system?
This is an Objective-C function that deals with NSFileManager class of the Cocoa framework.
/** Creates a folder in the filesystem.
@param folderNameOrPath String representing the folder name, optionally with its path (full or relative).
@return Returns true if success, false otherwise.
@see createFolderInDocumentDirectoryWithName:
@see createFolderInTempDirectoryWithName:
@see documentsDirectory
*/
+ (BOOL)createFolderWithName:(NSString *)folderNameOrPath {
if (![[NSFileManager defaultManager] fileExistsAtPath:folderNameOrPath]) {
NSError *err = nil;
[[NSFileManager defaultManager] createDirectoryAtPath:folderNameOrPath withIntermediateDirectories:YES attributes:nil error:&err];
if (err != nil) {
LogError(@"Error creating the folder '%@'", folderNameOrPath);
return NO;
}
}
return YES;
}
Download the ready-for-use source file (.m) of Create directory in iOS file system
No comments:
Post a Comment