Created
March 13, 2017 18:47
-
-
Save Adnan1990/8f763fb41489f5d9fc5bc33f1b5c33f1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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