I'm trying to copy or move a JPG from one folder to another using the code below.
func moveItems(originPath: String, destinationPath: String, successBlock:@escaping () -> Void, errorBlock:@escaping (_ error: Error) -> Void) {
do {
try FileManager.default.copyItem(atPath: originPath, toPath: destinationPath)
successBlock()
} catch {
print(error.localizedDescription)
errorBlock(NSError())
}
}
But i always get the following error:
open on /var/mobile/Containers/Data/Application/E138FDE0-A036-48D9-8E7C-518B6A5E452C/Documents/tailsImages/: File exists “3A75A51A-0946-45AF-BF1D-F4EB4D71ED68.png” couldn’t be copied to “Documents” because an item with the same name already exists.
There are two problems that I don't understand. One is that the destination folder isn't the "Documents" that the error refers and the other is that the JPG only exists in the destinationPath folder.
(lldb) po originPath "/var/mobile/Containers/Data/Application/E138FDE0-A036-48D9-8E7C-518B6A5E452C/Documents/tailsImagesSync/3A75A51A-0946-45AF-BF1D-F4EB4D71ED68.png"
(lldb) po destinationPath "/var/mobile/Containers/Data/Application/E138FDE0-A036-48D9-8E7C-518B6A5E452C/Documents/tailsImages/"
You should append filename in destinationPath. This will work for you.