Get the modification (or creation) date of a file

Xcode 10, Swift 4.2, macOS 10.13 func fileModificationDate(url: URL) -> Date? { do { let attr = try FileManager.default.attributesOfItem(atPath: url.path) return attr[FileAttributeKey.modificationDate] as? Date } catch { return nil } } FileAttributeKey.creationDate works exactly the same; .size and .type might also be of interest. This beautiful and elegant solution comes from this Stackoverflow answer and […]