feat: Populate LocalFile with real info

This commit is contained in:
ronaldheft 2022-07-30 16:22:41 -04:00
parent db7a8cef77
commit fec1ec554b
4 changed files with 38 additions and 13 deletions

View file

@ -42,3 +42,26 @@ extension DispatchQueue {
}
}
}
extension URL {
var attributes: [FileAttributeKey : Any]? {
do {
return try FileManager.default.attributesOfItem(atPath: path)
} catch let error as NSError {
print("FileAttribute error: \(error)")
}
return nil
}
var fileSize: Int64 {
return attributes?[.size] as? Int64 ?? Int64(0)
}
var fileSizeString: String {
return ByteCountFormatter.string(fromByteCount: Int64(fileSize), countStyle: .file)
}
var creationDate: Date? {
return attributes?[.creationDate] as? Date
}
}