Skip to content

Instantly share code, notes, and snippets.

@TomLiu
Created October 26, 2013 13:28
Show Gist options
  • Save TomLiu/7169481 to your computer and use it in GitHub Desktop.
Save TomLiu/7169481 to your computer and use it in GitHub Desktop.
Caculate a folder size
NSArray *filesArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:cachePath error:&error];
NSEnumerator *filesEnumerator = [filesArray objectEnumerator];
NSString *fileName;
unsigned long long int fileSize = 0;
while (fileName = [filesEnumerator nextObject]) {
NSString *filePath = [cachePath stringByAppendingPathComponent:fileName];
NSDictionary *fileDictionary = [fm attributesOfItemAtPath:filePath error:&error];
fileSize += [fileDictionary fileSize];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment