• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: createDirectoryAtPath problems
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.
References: 
 >createDirectoryAtPath problems (From: Mathew Peterson <email@hidden>)

  • Prev by Date: Re: createDirectoryAtPath problems
  • Next by Date: Re: createDirectoryAtPath problems
  • Previous by thread: Re: createDirectoryAtPath problems
  • Next by thread: Re: createDirectoryAtPath problems
  • Index(es):
    • Date
    • Thread