• 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: Making all components in path
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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
References: 
 >Making all components in path (From: "Paul J. Lucas" <email@hidden>)

  • Prev by Date: Making all components in path
  • Next by Date: newbie coredata NSManagedObjectModel empty
  • Previous by thread: Making all components in path
  • Next by thread: newbie coredata NSManagedObjectModel empty
  • Index(es):
    • Date
    • Thread