26 lines
608 B
Swift
26 lines
608 B
Swift
|
import Foundation
|
||
|
|
||
|
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: Int {
|
||
|
return Int(attributes?[.size] as? UInt64 ?? 0)
|
||
|
}
|
||
|
|
||
|
var fileSizeString: String {
|
||
|
return ByteCountFormatter.string(fromByteCount: Int64(fileSize), countStyle: .file)
|
||
|
}
|
||
|
|
||
|
var creationDate: Date? {
|
||
|
return attributes?[.creationDate] as? Date
|
||
|
}
|
||
|
}
|