Re: createDirectoryAtPath problems
Re: createDirectoryAtPath problems
- Subject: Re: createDirectoryAtPath problems
- From: Dan Wood <email@hidden>
- Date: Tue, 04 Feb 2003 22:09:20 -0800
You can't create a full path, this function only creates one directory
inside an existing directory.
Here's a category method on NSFileManager that I wrote to build up the
intermediate directories for you. Feel free to make use of it.
/*" Similar to -[NSFileManager createDirectoryAtPath:attributes:] but
parent directory doesn't have to exist; this does it for you. You must
pass in a standardized path; e.g. no ~ is allowed.
"*/
- (BOOL) createDirectoriesAtPath:(NSString *)inPath
attributes:(NSDictionary *)inAttributes
{
NSArray *components = [inPath pathComponents];
int i;
BOOL result = YES;
for (i = 1 ; i <= [components count] ; i++ )
{
NSArray *subComponents = [components subarrayWithRange:
NSMakeRange(0,i)];
NSString *subPath = [NSString pathWithComponents:subComponents];
BOOL isDir;
BOOL exists = [[NSFileManager defaultManager]
fileExistsAtPath:subPath isDirectory:&isDir];
if (!exists)
{
result = [[NSFileManager defaultManager]
createDirectoryAtPath:subPath attributes:inAttributes];
if (!result)
{
return result;
}
}
}
return result;
}
On Tuesday, February 4, 2003, at 07:09 PM, Mathew Peterson wrote:
Hi,
I am trying to create a directory in ~/Library/Application Support
called DevKit.
Here is what I have done:
bool i;
NSString *directoryLocation = [[NSString alloc]
initWithFormat:@"~/Library/Application Support/DevKit/"];
[directoryLocation stringByExpandingTildeInPath];
NSFileManager *man = [NSFileManager defaultManager];
i = [man createDirectoryAtPath:directoryLocation attributes:nil];
NSLog(@"%@", i);
It keeps returning (null). What am i doing wrong?
Mat
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
--
Dan Wood
Karelia Software, LLC
email@hidden
http://www.karelia.com/
Watson for Mac OS X:
http://www.karelia.com/watson/
The information contained in this message or any of its attachments may
be privileged and confidential and intended for the exclusive use of
the addressee(s). Any disclosure, reproduction, distribution or other
dissemination or use of this communication is strictly prohibited.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.