Re: Get size of folder
Re: Get size of folder
- Subject: Re: Get size of folder
- From: Dave DeLong <email@hidden>
- Date: Wed, 19 Aug 2009 20:20:24 -0600
Thanks for pointing that out, Bill. I was requesting the rsrc size
but then never actually doing anything with it.
I've got a better version now (which I've written as part of my
efforts to create an open source "Super Get Info" replacement), which
I explain in this SO.com post:
http://stackoverflow.com/questions/1289532#1303571
Dave
On Aug 19, 2009, at 11:14 AM, Bill Monk wrote:
PCWiz wrote:
The next thing I tried was using the Carbon File Manager API
using this method by Dave DeLong:
http://github.com/davedelong/BuildCleaner/blob/b2712242b4eea1fff0e78a08b393a417e3019c8a/NSFileManager+FileSize.m
This method worked for some folders/files, but for others it returned
wildly innacurate numbers
That code won't work for your purposes. It ignores the size of
resource forks. And its crux
// add the size for this item
totalSize += fetchedInfos
[thisIndex].dataLogicalSize;
counts only the *logical* file size. Recall that even a 1-character
file still uses a full physical allocation block on disk, and the
allocation block size varies depending upon device capacity,
partitioning scheme, etc.
To replicate Finder's displayed file sizes, you need the *physical*
on-disk sizes of all forks in a file, not their logical sizes.
That's irrelevant.
The method I'm using right now is probably the closest I've ever
gotten:
No need to reinvent this wheel. Pass an FSRef to your directory of
interest (or even the disk's root directory) to
OSErr FSIterateForks (
const FSRef *ref,
CatPositionRec *forkIterator,
HFSUniStr255 *forkName,
SInt64 *forkSize,
UInt64 *forkPhysicalSize
);
and loop, adding up everything it returns in its last parameter. Or
use FSGetCatalogInfo et. al. just be sure to use the physical fork
sizes. Though note that FSIterateForks saves dealing with the
(highly unlikely at this point, but still) possibility of files with
named forks that aren't the data fork -or- the resource fork!
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden