Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the path/directory component from a NSURL?

Tags:

macos

cocoa

nsurl

I retrieved a NSURL from a NSSavePanel. I now have this NSURL which gives me the following:

file://localhost/Users/brett/Documents/asdf%20asdf.json

Now, it is easy for me to retrieve just the filename using something like the following:

[[[NSFileManager defaultManager] displayNameAtPath:pathAndFilename] stringByDeletingPathExtension]

This gives me just the localized filename, as expected: asdf%20asdf

So, how do I get the path, like so: file://localhost/Users/brett/Documents/

like image 978
Brett Avatar asked Oct 04 '12 01:10

Brett


People also ask

What is a path directory?

Path. A path is a slash-separated list of directory names followed by either a directory name or a file name. A directory is the same as a folder.

What is Nsurl?

An NSURL object is composed of two parts—a potentially nil base URL and a string that is resolved relative to the base URL. An NSURL object is considered absolute if its string part is fully resolved without a base; all other URLs are considered relative.


1 Answers

-[NSURL URLByDeletingLastPathComponent] is the simplest way to achieve this.

like image 93
Mike Abdullah Avatar answered Nov 15 '22 14:11

Mike Abdullah