在 iPhone 上的 Objective-C 中,我尝试使用 NSFileManager。我无法弄清楚它从哪个目录开始
我的问题是, NSFileManager 从哪个目录开始,我真的很困惑,因为当我运行代码来告诉我所在的目录时,它只输出 /。另外,我可以将目录更改为 /private/var,但不能更改为 /mobile 和 /mobile/applications,这是应用程序所在的位置。下面是我的代码。
<代码> 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;
提前致谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
iOS 上的所有应用程序都是沙盒的。这意味着他们有自己的小沙箱可以玩(每个应用程序都有自己的文件夹)。 “/”代表应用程序沙箱文件夹的根目录。稍微引用一下 Amorya 的话,您无法写入 /private/var ,因为这样您就使应用程序的沙箱要求无效(您无法在那里写入或读取)。
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).