Search code examples
objective-ccocoasizedirectorymacos-carbon

Size discrepancy between size of folder from Finder and from Carbon file manager


I'm using this method by Dave DeLong to calculate the size of a folder using the Carbon File Manager API:

http://github.com/davedelong/BuildCleaner/blob/b2712242b4eea1fff0e78a08b393a417e3019c8a/NSFileManager+FileSize.m

(Its the first method there)

The issue I'm having is that some folders (.app bundles in my case) are not reporting the correct size. For example, DiskWarrior is 8.2MB, and the method reports 6.6MB

Any ideas on why this is happening?

THANKS


Solution

  • The Finder will report file sizes rounded to the nearest multiple of the block size (usually 4 KB) followed by the real size in bytes, and many (most) applications are bundles of files, so the true size of the application may be far smaller than the size shown as the first ("on disk") value.

    You can test this out by doing something (in the Terminal) like:

    echo -n 'foo' > foo.txt

    If you Get Info on this file in the Finder, it will report the size as "4 KB on disk (3 bytes)".