Re: Filename of File Relative to Directory It's In
Re: Filename of File Relative to Directory It's In
- Subject: Re: Filename of File Relative to Directory It's In
- From: email@hidden
- Date: Wed, 6 Mar 2002 22:33:00 -0800
I'd like to get the filename of a file relative to the directory that
it's in (for example, /Application/iTunes.app becomes iTunes or
iTunes.app; ideally there would be some way to know if the extension on
the given file was hidden or not).
Look at the category methods on NSString in NSPathUtilities.h. I
believe the one you want is -lastPathComponent:
- (NSString *)lastPathComponent;
For the extension thing, you'd use NSFileManager ([NSFileManager
defaultManager]) to get the attributes on the file
(fileAttributesAtPath:traverseLink:), and whether the extension was
hidden or not would be among the attributes (NSFileExtensionHidden).
Once you know whether you want the extension or not, you can use:
- (NSString *)pathExtension;
- (NSString *)stringByDeletingPathExtension;
- (NSString *)stringByAppendingPathExtension:(NSString *)str;
(also in NSPathUtilities.h) to futz around with it as you like. Good
luck...
Ben Haller
Stick Software
_______________________________________________
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.