Convert an NSString containing a URL to a POSIX path

I am working on extracting the POSIX path to a folder or file from NSPathControl after deleting the file or folder on it.

I am new, but I managed to get the value from the control (called Destination ) in my code as follows:

 NSString *filepath; filepath = [Destination stringValue]; 

It gives me something like

  file: // test / My% 20New% 20Project / 

but I would like to have it in the form of a POSIX path:

  / test / My New Project 
because I need to pass it to NSTask using the command line.

Any suggestion on how to convert the contents of this NSString from a URL format to a POSIX path?

+7
source share
1 answer

Use -URL instead of -stringValue . This will return an NSURL object representing the path displayed by the trace control. You can then send -path to the -path object to get its string representation without a URL / escaping scheme. For example:

 NSURL *fileURL = [Destination URL]; NSString *filepath = [fileURL path]; 

or

 NSString *filepath = [[Destination URL] path]; 
+17
source

All Articles