Last active
May 24, 2021 17:12
-
-
Save Farini/e68d0cf8bbd627cdb81e828d34fc505d to your computer and use it in GitHub Desktop.
Last modified + created date property of a file
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
/// 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