问题
I am trying to create a new directory and put files into it. However, I'm getting
Error Domain=NSCocoaErrorDomain Code=257 "The file “Offline” couldn’t be opened because you don’t have permission to view it."
I am able to create this new directory and the file exists.
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)
}
}
回答1:
You cannot move a file to a directory without appending the file name
do {
let fileName = localUrl.lastPathComponent
let offlineURL = offlinePath.appendingPathComponent(fileName)
try fileManager.moveItem(at: localUrl, to: offlineURL)
file.localUrl = offlineURL
} ...
来源:https://stackoverflow.com/questions/54523489/how-to-access-created-directory-nscocoaerrordomain-code-257