Skip to content

Instantly share code, notes, and snippets.

@shanecowherd
Last active November 12, 2019 23:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shanecowherd/87bfa7cc3e6030f2f687cc04bbff5e9a to your computer and use it in GitHub Desktop.
Save shanecowherd/87bfa7cc3e6030f2f687cc04bbff5e9a to your computer and use it in GitHub Desktop.
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