Re: Very simple - UNIX like - filename expansion?
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