我想知道: 用户点击按钮>取景器窗口将打开>用户选择一个或多个文件>并且此选定的文件/文件应复制到文档文件夹中。
我现在所拥有的:
@IBAction func copyFile(_ sender: Any) {
let dialog = NSOpenPanel();
dialog.showsHiddenFiles = false
dialog.canChooseDirectories = false
dialog.canCreateDirectories = false
dialog.allowsMultipleSelection = true
dialog.allowedFileTypes = ["pdf","doc","docx"]
if (dialog.runModal() == NSModalResponseOK) {
for x in 0..<dialog.urls.count {
// documents folder path
let dictDocuments = NSURL(fileURLWithPath: NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0])
// folder name
let logsPath = dictDocuments.appendingPathComponent("Files/")
print("SOURCE: ",dialog.urls[x].absoluteURL)
print("TARGET: ",logsPath!)
do {
try FileManager.default.copyItem(at: dialog.urls[x].absoluteURL, to: logsPath!)
} catch let error as NSError {}
}
} else {
return
}
}
这是输出:
SOURCE: file:///Users/XXX/Downloads/test.pdf
TARGET: file:///Users/XXX/Documents/Files/
open on /Users/XXX/Documents/Files: File exists
文件夹&#34; Files&#34;存在,但它是空的。 我错了什么?