• 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: Very simple - UNIX like - filename expansion?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Very simple - UNIX like - filename expansion?


  • Subject: Re: Very simple - UNIX like - filename expansion?
  • From: John Stiles <email@hidden>
  • Date: Mon, 23 May 2005 13:33:02 -0700

Remember that -cString is deprecated. Use -fileSystemRepresentation instead. For +stringWithCString I don't remember the equivalent for file-system-representation offhand, but stringWithUTF8String would work.


On May 23, 2005, at 12:52 PM, Joshua Minor wrote:

Marten van Gelderen wrote:

 I needed a very simple - UNIX like - filename expansion in my App


I suggest wrapping the POSIX glob function like this:

/* Return an array of pathnames that match a shell-like pattern.
 * The pattern may contain *, ?, ~ or [...] wildcards.
 * See the manual page for bash or glob(3) for more details.
 */
- (NSArray*)pathsMatchingPattern:(NSString*)pattern {

    NSMutableArray* result = [NSMutableArray array];

glob_t g;
glob([pattern cString], GLOB_NOSORT|GLOB_TILDE|GLOB_QUOTE, NULL, &g);


    int i;
    for (i=0; i<g.gl_pathc; i++) {
        NSString* path = [NSString stringWithCString:g.gl_pathv[i]];
        [result addObject:path];
    }

    globfree(&g);

    return result;
}

This might fit nicely in a category on NSFileManager.

-joshm

Joshua Minor
Graphics Software Engineer
Pixar Animation Studios

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40blizzard.com


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: 
 >Re: Very simple - UNIX like - filename expansion? (From: Joshua Minor <email@hidden>)

  • Prev by Date: Re: if an NSWindow is a drawer, how can I find the NSDrawer instance?
  • Next by Date: Should I add properties to ABPerson?
  • Previous by thread: Re: Very simple - UNIX like - filename expansion?
  • Next by thread: Re: Very simple - UNIX like - filename expansion?
  • Index(es):
    • Date
    • Thread