I\'m building a simple program in Swift, it should copy files with a certain extension to a different folder. If this folder exist the program will just copy them in the fol
From the copyItemAtPath(...) documentation:
dstPath
The path at which to place the copy ofsrcPath
. This path must include the name of the file or directory in its new location. ...
You have to append the file name to the destination directory for the
copyItemAtPath()
call (code updated for Swift 3 and later)
let srcURL = URL(fileURLWithPath: fullElementPath)
let destURL = URL(fileURLWithPath: newMTSFolder).appendingPathComponent(srcURL.lastPathComponent)
do {
try FileManager.default.copyItem(at: srcURL, to: destURL)
} catch {
print("copy failed:", error.localizedDescription)
}