I'm working on retrieving a POSIX path to a folder or file from an NSPathControl
after dropping the file or folder onto it.
I'm a beginner, but I was able to get the value from the control (called Destination
) in my code this way:
NSString *filepath;
filepath = [Destination stringValue];
This gives me something like
file://test/My%20New%20Project/
but I'd like to have it in the POSIX path form:
/test/My New Projectbecause I need to pass it to a
NSTask
running a command-line program.
Any suggestion about how to convert the content of this NSString
from an URL format to a POSIX path?
Use
-URL
instead of-stringValue
. That will return anNSURL
object representing the path displayed by the path control. You can then send-path
to theNSURL
object to obtain its string representation without the URL scheme/escaping. For instance:or