• 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: Best way to get a file path for presentation to the user
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Best way to get a file path for presentation to the user


  • Subject: Re: Best way to get a file path for presentation to the user
  • From: Jens Alfke <email@hidden>
  • Date: Fri, 18 Dec 2015 10:23:42 -0800

> On Dec 18, 2015, at 1:24 AM, Graham Cox <email@hidden> wrote:
>
> I want to display a path to the user. I have a URL, I need to show the local file path that represents (it’s always a local file path), where the /Users/<username>/ is replaced by ~/

The best methods for this are in NSFileManager:

/* displayNameAtPath: returns an NSString suitable for presentation to the user. For directories which have localization information, this will return the appropriate localized string. This string is not suitable for passing to anything that must interact with the filesystem.
 */
- (NSString *)displayNameAtPath:(NSString *)path;

/* componentsToDisplayForPath: returns an NSArray of display names for the path provided. Localization will occur as in displayNameAtPath: above. This array cannot and should not be reassembled into an usable filesystem path for any kind of access.
 */
- (nullable NSArray<NSString *> *)componentsToDisplayForPath:(NSString *)path;

There are other transformations to the path for display besides “~”. For example, the user should never see “/Volumes”, or hidden suffixes like “.app”. And some names get completely localized for display — the “Downloads” directory looks like “Dvökhn¶r” in Elbonian, for example.

—Jens
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: Best way to get a file path for presentation to the user
      • From: Graham Cox <email@hidden>
    • Re: Best way to get a file path for presentation to the user
      • From: Ken Thomases <email@hidden>
References: 
 >Best way to get a file path for presentation to the user (From: Graham Cox <email@hidden>)

  • Prev by Date: Re: CGContextClipToRects: invalid context 0x0.
  • Next by Date: Re: Environment woes executing scripts from my OS X app
  • Previous by thread: Re: Best way to get a file path for presentation to the user
  • Next by thread: Re: Best way to get a file path for presentation to the user
  • Index(es):
    • Date
    • Thread