> On 19 Dec 2015, at 5:23 AM, Jens Alfke <j...@mooseyard.com> wrote: > > >> On Dec 18, 2015, at 1:24 AM, Graham Cox <graham....@bigpond.com> 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
Ah, thanks - I was looking through NSFileManager but somehow overlooked these. My use case is an interface that sets up a batch of files for saving in a particular folder. The user chooses the folder using a standard NSOpenPanel, but I want to display the chosen location in the UI so that they don’t need to remember it. I don’t think a NSPathControl is really appropriate for this. But I do want the string to be the most understandable for the user. I don’t know really how many average users understand what ~/ means, but it’s probably the best I can do. —Graham _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com