While working on Permanent Eraser 2.4.1, I began researching for a more efficient way to find the size of a folder and its contents. The method I was using before worked for the most part, but it was slow and not always perfect. The FolderSize project makes use of three different methods (Cocoa + Carbon, Carbon, and UNIX) and determines their capabilities.
For this experiment, I had three critical requirements when getting the size of a folder and its contents.
This particular method I wrote for earlier versions of Permanent Eraser (version 2.4.0 and earlier). I tried to use Cocoa as much as possible by using the (slow) NSDirectoryEnumerator
. A small smattering of Carbon is used to properly get the proper size of files which also contain resource forks.
NSDirectoryEnumerator
is quite slow in comparison to the other two methods. Where the other two methods could size a folder in the blink of an eye, the Cocoa + Carbon method could be noticeably slower.Unfortunately, a (mostly) pure Cocoa way has displayed problems on all three counts.
This is a modified implementation of the fastFolderSizeAtFSRef
by Daniel Jalkut, posted on Apple's Cocoa mailing list in May 2005. I began using this method to get a file or folder's size starting with Permanent Eraser 2.4.1.
The function sizeForFolderStat
comes from Chapter 9 of the book Advanced Mac OS X Programming by Aaron Hillegass and Mark Dalrymple. This makes use of straight C code, instead of implementing Carbon or Cocoa routines.
Hands down, the best method was Carbon. I never encountered any problems when running it, it was correct, and it was fast.
These links represent other material I discovered during my research, but did not explicitly use for the FolderSize project.
fastFolderSizeAtFSRef
by Larry Lawrence Sanbourne