使用 NSFileManager 重命名文件时出现奇怪的错误

发布于 2024-09-18 16:54:34 字数 649 浏览 6 评论 0原文

我曾经使用以下命令来使用各种用户输入的值(BOOL,大多数是字符串)重命名 aplist 文件:

    [manager moveItemAtPath:oldPath toPath:newPath error:&error];

并且由于某些原因,在 iOS4+ 中,此问题会出现问题,因此我尝试以下操作:

 [1]  [manager copyItemAtPath:oldPath toPath:newPath error:&error];
 [2]  [manager removeItemAtPath:oldPath error:&error];

现在,[1] 复制 plist 和所有数据正确。 (我在注释掉[2]时已经验证过。但是由于某种原因,当我尝试[1]和[2]时,文件/出现/被重命名,但是,只有某些字段丢失,例如I FName和LName 保持不变,而 Phone1、Phone2、Email1、Email2 和 Website 则从新文件中删除

对于我来说,我就是无法弄清楚为什么当我尝试删除旧文件时​​只保留一些数据。创建新文件后的文件?

非常感谢任何帮助!

我只是想重命名 plist 文件,同时保持所有数据完好无损。

I used to use the following to rename aplist file with various user inputted values (BOOL,Strings mostly):

    [manager moveItemAtPath:oldPath toPath:newPath error:&error];

And for some reason in iOS4+ this glitches out, so I Attempt the following:

 [1]  [manager copyItemAtPath:oldPath toPath:newPath error:&error];
 [2]  [manager removeItemAtPath:oldPath error:&error];

Now, [1] copies the plist and ALL of the data correctly. (I've verified when commenting out [2]. But for some reason, when I attempt [1] & [2], the file /appears/ renamed, however, there are only certain fields missing, for example I FName and LName stay intact, whereas Phone1,Phone2,Email1,Email2 and Website are removed from the new file.

For the life of me, I just cannot figure out why only some of the data remains when I attempt a removeFileAtPath for the OLD file AFTER the NEW FILE is created?

Any help would be MUCH APPRECIATED!

I just simply want to rename a plist file, while keeping ALL of the data in tact.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦途 2024-09-25 16:54:35
NSString *newPath = [[oldPath stringByDeletingLastPathComponent] stringByAppendingPathComponent:newFilename];

[[NSFileManager defaultManager] movePath:oldPath toPath:newPath handler:nil];
NSString *newPath = [[oldPath stringByDeletingLastPathComponent] stringByAppendingPathComponent:newFilename];

[[NSFileManager defaultManager] movePath:oldPath toPath:newPath handler:nil];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文