开发者

NSFilemanager one directory back?

开发者 https://www.devze.com 2023-01-16 12:25 出处:网络
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

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];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号