Created
January 14, 2015 14:30
-
-
Save goocarlos/16c13397ec69f32679d3 to your computer and use it in GitHub Desktop.
folderSize Swift Implementation
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
class func folderSize(folderPath:String) -> UInt{ | |
// @see http://stackoverflow.com/questions/2188469/calculate-the-size-of-a-folder | |
let filesArray:[String] = NSFileManager.defaultManager().subpathsOfDirectoryAtPath(folderPath, error: nil)! as [String] | |
var fileSize:UInt = 0 | |
for fileName in filesArray{ | |
let filePath = folderPath.stringByAppendingPathComponent(fileName) | |
let fileDictionary:NSDictionary = NSFileManager.defaultManager().attributesOfItemAtPath(filePath, error: nil)! | |
fileSize += UInt(fileDictionary.fileSize()) | |
} | |
return fileSize | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks a lot
For Swift 5, and for people who want more than folder size :)