Skip to content

Instantly share code, notes, and snippets.

@Adnan1990
Created March 13, 2017 18:47
Show Gist options
  • Save Adnan1990/8f763fb41489f5d9fc5bc33f1b5c33f1 to your computer and use it in GitHub Desktop.
Save Adnan1990/8f763fb41489f5d9fc5bc33f1b5c33f1 to your computer and use it in GitHub Desktop.
func renameFile(oldName:String , newName : String){
do {
let originPath = (self.getDirectoryPath() as NSString).appendingPathComponent(oldName)
let destinationPath = (self.getDirectoryPath() as NSString).appendingPathComponent(newName)
try FileManager.default.moveItem(at: URL(fileURLWithPath: originPath), to: URL(fileURLWithPath: destinationPath))
} catch {
print(error)
}
}
func getDirectoryPath() -> String {
let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
let documentsDirectory = paths[0]
return documentsDirectory
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment