• 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: Joshua Minor <email@hidden>
  • Date: Mon, 23 May 2005 12:52:14 -0700

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Very simple - UNIX like - filename expansion?
      • From: glenn andreas <email@hidden>
    • Re: Very simple - UNIX like - filename expansion?
      • From: John Stiles <email@hidden>
  • Prev by Date: NSOutlineView initial expanded status
  • Next by Date: ~/library/application support/myapp directory creation
  • Previous by thread: Re: NSOutlineView initial expanded status
  • Next by thread: Re: Very simple - UNIX like - filename expansion?
  • Index(es):
    • Date
    • Thread