Re: Creating directory at path, recursively
Re: Creating directory at path, recursively
- Subject: Re: Creating directory at path, recursively
- From: Jean-Nicolas Jolivet <email@hidden>
- Date: Thu, 13 Nov 2008 13:24:09 -0500
hehe, thanks this is working fine... I knew it was going to be
something obvious! :)
Jean-Nicolas Jolivet
On 13-Nov-08, at 1:11 PM, 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];
}
EG
-----Original Message-----
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...
------------------------------------------------------------
This message and any attachments (the "message") are confidential
and intended solely for the addressee(s). Any unauthorised use or
dissemination is prohibited. E-mails are susceptible to alteration.
Neither DxO Labs nor any of its subsidiaries or affiliates shall be
liable for the message if altered, changed or falsified.
Ce message et toutes les pieces jointes (ci-apres le "message") sont
confidentiels et etablis a l'intention exclusive de ses
destinataires. Toute utilisation ou diffusion non autorisee est
interdite. Tout message electronique est susceptible d'alteration.
DxO Labs et ses filiales declinent toute responsabilite au titre de
ce message s'il a ete altere, modifie ou falsifie.
_______________________________________________
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