废话不多说,直接上代码:
let filePath = "The file path"
do {
let dic: [FileAttributeKey: Any] = try FileManager.default.attributesOfItem(atPath: filePath)
let bytes = dic[FileAttributeKey.size]
print(bytes)
} catch {
// 异常处理
}
获取到的 size 是字节数,所以,
KB = bytes / 1024.0
MB = bytes / 1024.0 / 1024.0
GB = bytes / 1024.0 / 1024.0 / 1024.0
...
网友评论