Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Check if a file is bigger than 0 KB
func fileBiggerThan0KB(path: String) -> Bool {
do {
var fileSize : UInt64 = 0
//return [FileAttributeKey : Any]
let attr = try FileManager.default.attributesOfItem(atPath: path)
fileSize = attr[FileAttributeKey.size] as! UInt64
//if you convert to NSDictionary, you can get file size old way as well.
let dict = attr as NSDictionary
fileSize = dict.fileSize()
if fileSize > 0 {
return true
}
} catch {
}
return false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment