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