views:

31

answers:

2

Hello , 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 ?

+1  A: 

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:@".."];
imaginaryboy
Many thanks , it works perfectly :)
Kostas.N
A: 

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];
Shaggy Frog