如何访问创建的目录?- 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
} ... 

相关内容

  • 没有找到相关文章

最新更新