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: Chris Parker <email@hidden>
- Date: Wed, 6 Mar 2002 23:25:46 -0800
On Wednesday, March 6, 2002, at 10:33 PM, email@hidden wrote:
[Ben's quotation below is from Evan DiBiase on Wed Mar 06, 2002
08:46:26 PM US/Pacific]
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...
Actually, if all you want to do is be able to pick out the filename and
appropriately hide the extension you're probably looking for
displayNameAtPath:
- (NSString *)displayNameAtPath:(NSString *)path
Returns the name of the file or directory at path in a form appropriate
for presentation to the user. If there is no file or directory at path,
or an error occurs, [path lastPathComponent] is returned.
.chris
--
Chris Parker <email@hidden>
Cocoa Frameworks Engineer
_______________________________________________
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.