Last active
November 12, 2019 23:06
-
-
Save shanecowherd/87bfa7cc3e6030f2f687cc04bbff5e9a to your computer and use it in GitHub Desktop.
Check if a file is bigger than 0 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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