i want to know if there is a way to get the previous directory when working with NSFileManager... This can be probably done by appending '..' to the current directory ([[NSFileManager defaultManager] currentDirectoryPath] ) , but it's n开发者_如何学编程ot a good idea at all :(
Is there another effective way to do this ?
If what you're trying to do is just obtain the string representing the path of the parent directory then you could do this:
NSString* parentPath = [[[NSFileManager defaultManager] currentDirectoryPath] stringByDeletingLastPathComponent];
If you actually want to change to the parent directory, then just:
[[NSFileManager defaultManager] changeCurrentDirectoryPath:@".."];
Sure, just use the stringByDeletingLastPathComponent
method in NSString
. As per your question, you'd do something like:
NSFileManager* fileManager = [NSFileManager defaultManager];
NSString* currentDirectoryPath = [fileManager currentDirectoryPath];
NSString* previousDirectory = [currentDirectoryPath stringByDeletingLastPathComponent];
精彩评论