Skip to content

Instantly share code, notes, and snippets.

@Farini
Last active May 24, 2021 17:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Farini/e68d0cf8bbd627cdb81e828d34fc505d to your computer and use it in GitHub Desktop.
Save Farini/e68d0cf8bbd627cdb81e828d34fc505d to your computer and use it in GitHub Desktop.
Last modified + created date property of a file
/// Gets the Last Modified and Created Date of the file at path.
func fileDateAttributes(at path:String) -> (created:Date?, modified:Date?) {
do {
let attributes:[FileAttributeKey:Any] = try FileManager.default.attributesOfItem(atPath: path)
let modificationDate = attributes[FileAttributeKey.modificationDate] as? Date
let creationDate = attributes[FileAttributeKey.creationDate] as? Date
return (creationDate, modificationDate)
}catch{
print("Error getting attributes of file: \(path). Check if file exists and that the system can access its attributes.")
return (nil, nil)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment