How to access created Directory? - NSCocoaErrorDomain Code=257

我的梦境 提交于 2020-01-30 12:55:16

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!