Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Extracting file name & path from NSOpenPanel



Phil,

On 3.4.2006, at 0:12, Phil Faber wrote:

That's worked fine. Thanks a lot. I had discovered 'stringWithContentsOfFile' and was working on the assumption that I needed to find something equivalent such as:

NSString *content = [NSString stringWithFileName:[panel filename]];

You've got a good hunch -- in a sense, you do :)

Not for you debugging purposes, for such cases, plain

NSLog(@"about to open file: \"%@\"",[panel filename]);

or perhaps

NSRunAlertPanel(@"About to open a filename:",@"%@",nil,nil,nil,[panel filename]);

is completely sufficient and all right, but whilst the [panel filename] is a perfectly valid NSString containing the path useable in almost all situations -- it is not quite all right for the one you want to display the file name to the user. If so happens, what you need is

NSString *fileNameToBeShown=[[NSFileManager defaultManager] displayNameAtPath:[panel filename]];

The trick is the filesystem may change the real filename (returned by the NS*Panel -filename method) to somewhat mangled one for display purposes, like hiding suffixes, translating some folder names into the current language, and so forth...
---
Ondra Čada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc



_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >Re: Extracting file name & path from NSOpenPanel (From: "Bobby B" <email@hidden>)
 >Re: Extracting file name & path from NSOpenPanel (From: Phil Faber <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.