Caps-iOS/Caps/Extensions/URL+Extensions.swift
2022-06-10 21:20:49 +02:00

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
}
}