Replaceitemat Dsturl Url With Srcurl Url

[Solved] Replaceitemat Dsturl Url With Srcurl Url | Shell - Code Explorer | yomemimo.com
Question : replaceItem(at dstURL: URL, with srcURL: URL)

Answered by : happy-hyena-j4t6squdpbx2

let fileManager = FileManager.default
func copyItem(at srcURL: URL, to dstURL: URL) { do { try fileManager.copyItem(at: srcURL, to: dstURL) } catch let error as NSError { if error.code == NSFileWriteFileExistsError { print("File exists. Trying to replace") replaceItem(at: dstURL, with: srcURL) } }
}
func replaceItem(at dstURL: URL, with srcURL: URL) { do { try fileManager.removeItem(at: dstURL) copyItem(at: srcURL, to: dstURL) } catch let error as NSError { print(error.localizedDescription) }
}

Source : https://stackoverflow.com/questions/39930482/filemanager-replaceitemat-results-in-exc-bad-access | Last Update : Fri, 02 Jul 21

Answers related to replaceitemat dsturl url with srcurl url

Code Explorer Popular Question For Shell