• 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: Create a file and the path....
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Create a file and the path....
      • From: Paul Lynch <email@hidden>
References: 
 >Create a file and the path.... (From: Yorh <email@hidden>)

  • Prev by Date: Create a file and the path....
  • Next by Date: Re: Create a file and the path....
  • Previous by thread: Create a file and the path....
  • Next by thread: Re: Create a file and the path....
  • Index(es):
    • Date
    • Thread