Is there any way to find the parent directory of a path using NSFileManager
or something?
e.g. Take this:
/path/to/something
And turn it into
/path/to/
A folder that is one level up from the current directory in a file hierarchy.
The .. means “the parent directory” of your current directory, so you can use cd .. to go back (or up) one directory. cd ~ (the tilde). The ~ means the home directory, so this command will always change back to your home directory (the default directory in which the Terminal opens).
Get the Parent Directory in Python Using the path. parent() Method of the pathlib Module. The path. parent() method, as the name suggests, returns the parent directory of the given path passed as an argument in the form of a string.
The NSString
method -stringByDeletingLastPathComponent
does just that.
You can use it like this:
NSLog(@"%@", [@"/tmp/afolder" stringByDeletingLastPathComponent]);
And it will log /tmp
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With