gpt4 book ai didi

objective-c - copyItemAtPath 总是因文件存在错误而失败

转载 作者:太空狗 更新时间:2023-10-30 03:21:09 24 4
gpt4 key购买 nike

我正在尝试使用 copyItemAtPath 复制目录,但每次都失败并显示“操作无法完成。文件存在”错误。

这是我正在使用的代码

NSLog(@"Copying from: %@ to: %@", [[NSUserDefaults standardUserDefaults] objectForKey:@"template_1_path"], path);
if(![file_manager copyItemAtPath:[NSString stringWithFormat:@"%@", [[NSUserDefaults standardUserDefaults] objectForKey:@"template_1_path"]] toPath:[NSString stringWithFormat:@"%@", path] error:&error]) {
NSLog(@"%@" [error localizedDescription]);
}

日志示例-

"Copying from: /Users/testuser/Sites/example_site to: /Users/testuser/Desktop"
"The operation couldn’t be completed. File exists"

对我做错了什么有什么想法吗?

提前致谢!

最佳答案

您似乎正在尝试将文件“/Users/testuser/Sites/example_site”复制到文件“/Users/testuser/Desktop/example_site”,假设您可以指定目标目录并且它将使用源文件名。这是行不通的。郭思the documentation :

When a file is being copied, the destination path must end in a filename—there is no implicit adoption of the source filename.

关于objective-c - copyItemAtPath 总是因文件存在错误而失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5785184/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com