Change an URL relative to the absolute URL in Objective C

advertisements

How would I take a file in the application's directory (the same folder the .app is in), and get it's absolute path. Say the relative path is "Data/file.txt," how would I use Objective C to get that as an absolute path? I have the user enter their home folder name, if that is any help.

Please help,

HiGuy


Find the location of the running app by doing :

NSString * applicationPath = [[NSBundle mainBundle] bundlePath];

Which will return something like :

/Users/myUser/Library/Application Support/iPhone Simulator/User/Applications/317CF5C7-57B3-42CE-8DF4-4DD10B070D95/Assignment1a.app

Then use - (NSString *)stringByDeletingLastPathComponent to chop off the last bit.