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 protected])
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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [EMAIL PROTECTED]