开发者

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, 开发者_Python百科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.


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).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜