I\'m using this method to copy a file:
[fileManager copyItemAtPath:sourcePath toPath:targetPath error:&error];
I want to overwrite a fi
This is for improvement of 'Swift 3 and above' of question 'Move file and override [duplicate]' which is marked duplicate of this question.
To move file from sourcepath(string) to DestinationPath(string). Delete the existing file if same name file already exists at DestinationPath.
// Set the correct path in string in 'let' variables.
let destinationStringPath = ""
let sourceStringPath = ""
let fileManager:FileManager = FileManager.default
do
{
try fileManager.removeItem(atPath: sourceStringPath)
}
catch
{
}
do
{
try fileManager.moveItem(atPath: sourceStringPath, toPath: destinationStringPath)
}
catch
{
}