Skip to content

Instantly share code, notes, and snippets.

@shanecowherd
Last active November 12, 2019 23:06
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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