Re: Creating directory at path, recursively
Re: Creating directory at path, recursively
- Subject: Re: Creating directory at path, recursively
- From: Quincey Morris <email@hidden>
- Date: Thu, 13 Nov 2008 10:21:49 -0800
On Nov 13, 2008, at 10:11, Etienne Guérard wrote:
You might want to do it this way:
- (void)createDirectoryRecursivelyAtPath:(NSString *)path
{
//check if the dir just above exists...
NSFileManager *fileManager = [NSFileManager defaultManager];
BOOL isDir;
NSString *directoryAbove = [path stringByDeletingLastPathComponent];
if (![fileManager fileExistsAtPath:directoryAbove isDirectory:&isDir]
&& isDir)
{
// call ourself with the directory above...
[self createDirectoryRecursivelyAtPath:directoryAbove];
}
// Now we enforced that the dir exist
// Fine, create the dir...
[fileManager createDirectoryAtPath:path attributes:nil];
}
Or even this way: [[NSFileManager defaultManger]
createDirectoryAtPath: path withIntermediateDirectories: YES
attributes: nil error: &error]?
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden