move a file in swift

// Swift, file handling, move file

import Foundation

let fileManager = FileManager.default let sourceURL = URL(fileURLWithPath: "/path/to/source/file") let destinationURL = URL(fileURLWithPath: "/path/to/destination/file")

do { try fileManager.moveItem(at: sourceURL, to: destinationURL) print("File moved successfully") } catch let error { print("Error: (error.localizedDescription)") }

main.swift

Tags: Swift, file handling, move file, FileManager, URL.
58 chars
3 lines

related categories

gistlibby LogSnag