【发布时间】:2018-11-30 10:10:43
【问题描述】:
这是我的文件夹结构
我想将此 Stickers 文件夹复制到 文档目录,为此我使用了以下代码
let fileManager = FileManager.default
let documentsUrl = fileManager.urls(for: .documentDirectory,
in: .userDomainMask)
guard documentsUrl.count != 0 else {
return // Could not find documents URL
}
let finalDatabaseURL = documentsUrl.first!.appendingPathComponent("Stickers")
if !( (try? finalDatabaseURL.checkResourceIsReachable()) ?? false) {
print("DB does not exist in documents folder")
let documentsURL = Bundle.main.resourceURL?.appendingPathComponent("Stickers")
do {
try fileManager.copyItem(atPath: (documentsURL?.path)!, toPath: finalDatabaseURL.path)
} catch let error as NSError {
print("Couldn't copy file to final location! Error:\(error.description)")
}
} else {
print("Database file found at path: \(finalDatabaseURL.path)")
}
但它不会工作。我收到一个错误
注意:如果无法复制文件夹,那么我想将 Assets.xcassets 复制到 Document Directory。我怎样才能实现它?
【问题讨论】:
标签: ios mobile directory swift4 document-directory