Re: Making all components in path
Re: Making all components in path
- Subject: Re: Making all components in path
- From: Ryan Britton <email@hidden>
- Date: Wed, 12 Oct 2005 17:25:34 -0700
Here's what I've been using for that.
+ (BOOL)createNeededDirectoriesForPath:(NSString *)p withBasePath:
(NSString *)base andFileManager:(NSFileManager *)manager
{
NSArray *pathComponents = [p pathComponents];
NSEnumerator *e;
NSString *fullPath = [NSString stringWithString:base];
NSString *component;
BOOL isDir;
BOOL success = YES;
e = [pathComponents objectEnumerator];
while (component = [e nextObject])
{
if ([manager fileExistsAtPath:fullPath isDirectory:&isDir])
{
if (!isDir)
{
success = NO;
}
}
else //Doesn't exist, create the directory
{
success = (success && [manager
createDirectoryAtPath:fullPath attributes:nil]);
}
fullPath = [fullPath stringByAppendingPathComponent:component];
}
return success;
}
On Oct 12, 2005, at 5:02 PM, Paul J. Lucas wrote:
I was looking at NSFileManager and it doesn't seem to do all
that much with directory paths. I want to create a patch and
create any necessary intermediate paths, e.g.:
~/foo/bar/baz/
I want to create foo if it doesn't exist; create bar if it
doesn't exist; create baz if it doesn't exist; i.e., the
equivalent of the command-line command:
mkdir -p ~/foo/bar/baz/
- Paul
_______________________________________________
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
_______________________________________________
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