Very simple - UNIX like - filename expansion?
Very simple - UNIX like - filename expansion?
- Subject: Very simple - UNIX like - filename expansion?
- From: Marten van Gelderen <email@hidden>
- Date: Thu, 26 Feb 2004 16:17:45 +0100
Dear All,
I needed a very simple - UNIX like - filename expansion in my App. It
just had to accept a star as last character in an absolute path. So I
implemented:
@implementation NSString (MvG_PathExtensions)
- (NSString *)stringByDeletingSuffix:(NSString *)suffix
{
return [self hasSuffix: suffix] ? [self substringToIndex: [self
length] - [suffix length]] : self;
}
- (NSString *)stringByExpandingStarInPath
{
NSString *string;
return ([[self stringByDeletingSuffix: @"*"]
completePathIntoString: &string caseSensitive: YES
matchesIntoArray: NULL filterTypes: NULL] > 0) ? string : self;
}
@end
This almost works, except for the case where the matching directory
contains only one subdirectory. It then goes "one level" too far. I do
understand that this is the consequence of the "completePath..."
message which returns the "longest match" etc. etc.
My question is: am I on the right track and should I make
"-stringByExpandingStarInPath" a little smarter or is there an
alternative way/package/category that I am not aware of?
Thanks in advance...
--
Groeten, Marten
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.