Re: Create a file and the path....
Re: Create a file and the path....
- Subject: Re: Create a file and the path....
- From: Ryan Britton <email@hidden>
- Date: Wed, 22 Mar 2006 07:04:18 -0800
Not built in, no. You'll need to do that yourself. It's pretty
trivial to do though.
+ (BOOL)createNeededDirectoriesForPath:(NSString *)p withFileManager:
(NSFileManager *)manager
{
NSArray *pathComponents = [p pathComponents];
NSEnumerator *e;
NSString *rootPath = [NSString stringWithString:@"/"];
NSString *component;
BOOL isDir;
BOOL success = YES;
e = [pathComponents objectEnumerator];
while (component = [e nextObject])
{
if ([manager fileExistsAtPath:rootPath isDirectory:&isDir])
{
if (!isDir) //Something exists here but it's not a directory
{
success = NO;
}
}
else //Doesn't exist, create the directory
{
success = (success && [manager createDirectoryAtPath:rootPath
attributes:nil]);
}
rootPath = [rootPath stringByAppendingPathComponent:component];
}
return success;
}
On Mar 22, 2006, at 6:52 AM, Yorh wrote:
Hi,
I would like to create a file from a NSMutableDictionary that is
simple indeed...
I make the dictionary and then I use:
[myDict writeToFile:aPath atomically:YES];
The problem is that my aPath may be not exist yet....
Is there any method to create the file and all the path at one time?
Thank you all
Yorh
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden