Now I use this code to get the size of the folder:
NSArray *contents; NSEnumerator *enumerator; NSString *path; contents = [[NSFileManager defaultManager] subpathsAtPath:folderPath]; enumerator = [contents objectEnumerator]; while (path = [enumerator nextObject]) { NSDictionary *fattrib = [[NSFileManager defaultManager] fileAttributesAtPath:[folderPath stringByAppendingPathComponent:path] traverseLink:YES]; fileSize +=[fattrib fileSize]; } [contents release]; [path release];
The problem is that he is very dishonest. It either adds a few megabytes or subtracts several megabytes from the actual size. For example, I got the size of the .app package file, and this method reported 16.2MB, while the actual thing is 15.8.
What is the best way to get folder size?
thanks
objective-c folder cocoa size nsfilemanager
indragie
source share