Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing the file:/// prefix from URL path

How do I remove the file:/// prefix from the URL filepath:

 NSLog(@"File downloaded to: %@", filePath);

Currently it prints as:

file:///Users/Library/Developer/CoreSimulator/Devices/EF752245-9692-4607-B84C-6133202A846B/data/Containers/Data/Application/08686F05-C513-4BDF-A20C-EF3AE1201D54/Documents/2017-02-12_1476366438.zip

EDIT:

I guess I could have done:

NSLog(@"File downloaded to: %@", [[filePath absoluteString] stringByReplacingOccurrencesOfString:@"file:///" withString:@""]);

But isn't there anything build it to NSString that can remove that prefix?

like image 724
butter_baby Avatar asked Feb 13 '17 04:02

butter_baby


People also ask

Can a URL be a file path?

So yes, file URIs are URLs.

How do I delete a file in Linux path?

Type the rm command, a space, and then the name of the file you want to delete. If the file is not in the current working directory, provide a path to the file's location. You can pass more than one filename to rm . Doing so deletes all of the specified files.

How to remove the extension from the URL of a website?

Therefore, the URL of the website have a .html extension. The .html extension can be easily removed by editing the .htaccess file. .htaccess file: The .htaccess file is created with a Text Editor like Notepad. It is a simple ASCII file that lets the server know what configuration changes are to be made on a per-directory basis. Attention reader!

How to remove the htaccess extension from a URL?

Note: The .htaccess is the full name of the file. It is not file.htaccess, it is simply .htaccess. Removing .html Extension: To remove the .html extension from a URL. For example: Log in to cPanel account. In the Files section, click on the File Manager icon. Click on the Settings Button in the top right corner.

How to find the path of a file in chrome?

In the current Chrome 69 (69.0.3497.100 ) version, when user opens a file on their computer using Chrome, it will display an URL in the address bar that starts with file:// and then the path of the file is appended as shown below.

How to remove the html extension from a file?

The .html extension can be easily removed by editing the .htaccess file. .htaccess file: The .htaccess file is created with a Text Editor like Notepad. It is a simple ASCII file that lets the server know what configuration changes are to be made on a per-directory basis. Attention reader!


1 Answers

filePath.path is what you're looking for. You don't want to "remove file:///." You just want the path part of the URL.

Note that this will leave the first /. I guess you could remove that, but it's unclear why that would be a good idea, since it's part of the path. (If you're gluing this together with other strings that might end in /, it's better to use path methods like stringByAppendingPathComponent: to get rid of doubled-slashes.)

like image 98
Rob Napier Avatar answered Oct 28 '22 06:10

Rob Napier