Creating directory at path, recursively
Creating directory at path, recursively
- Subject: Creating directory at path, recursively
- From: Jean-Nicolas Jolivet <email@hidden>
- Date: Thu, 13 Nov 2008 13:01:58 -0500
I know there's a method to do just that in Leopard, however I want my
app to work on Tiger too, therefore I'm trying to put together a
simple "createDirectoryRecursivelyAtPath" method, however for some
reason it doesn't seem to work....
Here's a simplified version of my method:
- (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)
{
// Fine, create the dir...
[fileManager createDirectoryAtPath:path attributes:nil];
}
else
{
// call ourself with the directory above...
[self createDirectoryRecursivelyAtPath:directoryAbove];
}
}
Am I missing something? If I'm trying to create for example: /a/b/c
(and none of them exists) only /a is created...
Jean-Nicolas Jolivet
_______________________________________________
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