如何访问创建的目录? - NSCocoaErrorDomain代码= 257

问题描述 投票:0回答:1

我想创建一个新的目录,将文件放到它。但是,我越来越

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)
      }
 }
ios swift cocoa-touch nsfilemanager
1个回答
2
投票

你不能移动一个文件到一个目录不附加文件名

do {
    let fileName = localUrl.lastPathComponent
    let offlineURL = offlinePath.appendingPathComponent(fileName)
    try fileManager.moveItem(at: localUrl, to: offlineURL)
    file.localUrl = offlineURL
} ... 
© www.soinside.com 2019 - 2024. All rights reserved.