[ACCEPTED]-Find parent directory of a path-nsfilemanager
Accepted answer
The NSString
method -stringByDeletingLastPathComponent
does just that.
You can use 1 it like this:
NSLog(@"%@", [@"/tmp/afolder" stringByDeletingLastPathComponent]);
And it will log /tmp
.
Usually file URLs are of type NSURL
. There's 2 now a method you can use to grab the parent 1 directory:
NSURL *parentDirectory = [fileURL URLByDeletingLastPathComponent];
You should use URL for file locations. If 2 you have a path as String I would convert 1 it to URL. For Swift 3 use
let fileURL: URL = URL(fileURLWithPath: "/path/to/something")
let folderURL = fileURL.deletingLastPathComponent()
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.