Search code examples
iphoneobjective-cxcodeios4nsfilemanager

In objective-c on iPhone, I am attempting to use the NSFileManager. I can't figure out what directory it starts out in


My question is, what directory does the NSFileManager start out in, I am really confused because when I run code to tell me what directory I'm in, it just outputs /. Also I can change directory to /private/var but not into /mobile and /mobile/applications which is where the application is. Bellow is my code.

NSString *currentpath;

filemgr = [NSFileManager defaultManager];currentpath = [filemgr currentDirectoryPath];

NSLog (@"Current directory is %@", currentpath);

if ([filemgr changeCurrentDirectoryPath: @"/private/var/mobile"] == NO)
    NSLog (@"Cannot change directory.");

currentpath = [filemgr currentDirectoryPath];

NSLog (@"Current directory is %@", currentpath);
label.text = currentpath;

Thanks in advance.


Solution

  • All of the apps on iOS are sandboxed. That means that they have their own little sandbox to play around in (each app has its own folder). The "/" represents the root of the app's sandbox folder. Quoting Amorya a bit, you cannot write to /private/var because then you are invaliding the app's sandbox's requirements (you can't write there, or read).