• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Filename of File Relative to Directory It's In
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: Filename of File Relative to Directory It's In
      • From: Chris Parker <email@hidden>
  • Prev by Date: Re: Help Please?
  • Next by Date: Probably something dumb...
  • Previous by thread: Re: Filename of File Relative to Directory It's In
  • Next by thread: Re: Filename of File Relative to Directory It's In
  • Index(es):
    • Date
    • Thread