如何访问创建的目录? - NSCocoaErrorDomain 代码=257
How to access created Directory? - NSCocoaErrorDomain Code=257
我正在尝试创建一个新目录并将文件放入其中。但是,我得到
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
} ...
我正在尝试创建一个新目录并将文件放入其中。但是,我得到
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
} ...