Skip to content

Instantly share code, notes, and snippets.

@agammahajan1
Created September 6, 2020 09:11
Show Gist options
  • Save agammahajan1/944bb95257681d50667d578ad63af121 to your computer and use it in GitHub Desktop.
Save agammahajan1/944bb95257681d50667d578ad63af121 to your computer and use it in GitHub Desktop.
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: UInt64 {
return attributes?[.size] as? UInt64 ?? UInt64(0)
}
var fileSizeString: String {
return ByteCountFormatter.string(fromByteCount: Int64(fileSize), countStyle: .file)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment