Search code examples
iphoneobjective-cnsfilemanager

NSFilemanager one directory back?


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 not a good idea at all :(

Is there another effective way to do this ?


Solution

  • 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:@".."];