func usage() {
let url = NSURL(fileURLWithPath: "/")
let keys: [URLResourceKey] = [.volumeTotalCapacityKey, .volumeAvailableCapacityForImportantUsageKey]
guard let dict = try? url.resourceValues(forKeys: keys) else {
return
}
let total = (dict[URLResourceKey.volumeTotalCapacityKey] as! NSNumber).int64Value
let free = (dict[URLResourceKey.volumeAvailableCapacityForImportantUsageKey] as! NSNumber).int64Value
let totalStr = ByteCountFormatter.string(fromByteCount: total, countStyle: ByteCountFormatter.CountStyle.decimal)
let freeStr = ByteCountFormatter.string(fromByteCount: free, countStyle: ByteCountFormatter.CountStyle.decimal)
let usedStr = ByteCountFormatter.string(fromByteCount: total - free, countStyle: ByteCountFormatter.CountStyle.decimal)
Swift.print("Total: \(totalStr), Free: \(freeStr), Used: \(usedStr)")
}
// Total: 1 TB, Free: 637.46 GB, Used: 362.78 GB
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme