gpt4 book ai didi

ios - 如何访问创建的目录? - NSCocoaErrorDomain 代码=257

转载 作者:行者123 更新时间:2023-11-28 11:38:03 25 4
gpt4 key购买 nike

我正在尝试创建一个新目录并将文件放入其中。但是,我得到了

Error Domain=NSCocoaErrorDomain Code=257 "The file “Offline” couldn’t be opened because you don’t have permission to view it."

我能够创建这个新目录并且文件存在。

let offlinePath = fileDirectory.appendingPathComponent("Offline")
try? fileManager.createDirectory(at: offlinePath, withIntermediateDirectories: true, attributes: nil)

files.forEach { file in
if let localUrl = file.localUrl {
do {
try fileManager.moveItem(at: localUrl, to: offlinePath)
file.localUrl = offlinePath
} catch {
print(error)
}
}

最佳答案

如果不附加文件名,则不能将文件移动到目录

do {
let fileName = localUrl.lastPathComponent
let offlineURL = offlinePath.appendingPathComponent(fileName)
try fileManager.moveItem(at: localUrl, to: offlineURL)
file.localUrl = offlineURL
} ...

关于ios - 如何访问创建的目录? - NSCocoaErrorDomain 代码=257,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54523489/

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