現在,我使用這個代碼來獲得一個文件夾的大小:獲取文件夾大小的簡單方法(ObjC/Cocoa)?
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];
的問題是,它的高度innacurate。它要麼增加幾兆字節,要麼從實際大小中減去幾兆字節。例如,我得到一個.app包的文件大小,這個方法報告了16.2MB,而實際的東西是15.8。
獲取文件夾大小的最佳方法是什麼?
謝謝
有人嗎? :-) – 2011-12-01 22:59:42