【问题标题】:How to access created Directory? - NSCocoaErrorDomain Code=257如何访问创建的目录? - NSCocoaErrorDomain 代码=257
【发布时间】:2019-06-28 15:03:22
【问题描述】:

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

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)
      }
 }

【问题讨论】:

  • 什么是fileDirectory
  • @vadian fileDirectory 是我存储文件的 URL
  • 我知道这是一个 URL,但它的位置是什么?
  • @JoshCaswell 不确定沙盒是什么意思。这是在 iOS 上

标签: ios swift cocoa-touch nsfilemanager


【解决方案1】:

您不能在不附加文件名的情况下将文件移动到目录

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

【讨论】:

  • 这解决了我的问题。谢谢,我希望错误更清楚。
  • 其实很清楚:文件“离线”...
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-05-11
  • 2021-12-24
  • 2016-06-14
  • 2012-04-23
  • 2013-11-11
  • 2015-01-11
  • 2014-09-13
相关资源
最近更新 更多