|
| [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] |
On May 20, 2005, at 9:09 AM, Julian wrote:
I don't think there's anything that does it all for you. I use Carbon to iterate, which is must faster than using NSEnumerator, but it still may not be the best way. Note my comment about the resource forks. The application I'm using this in doesn't grab the resource forks so it doesn't care about their size. - (unsigned long long) fastFolderSizeAtFSRef:(FSRef*)theFileRef { FSIterator thisDirEnum = NULL; unsigned long long totalSize = 0; // Iterate the directory contents, recursing as necessary if (FSOpenIterator(theFileRef, kFSIterateFlat, &thisDirEnum) == noErr) { const ItemCount kMaxEntriesPerFetch = 256; ItemCount actualFetched; FSRef fetchedRefs[kMaxEntriesPerFetch]; FSCatalogInfo fetchedInfos[kMaxEntriesPerFetch]; // DCJ Note right now this is only fetching data fork sizes... if we decide to include // resource forks we will have to add kFSCatInfoRsrcSizes OSErr fsErr = FSGetCatalogInfoBulk(thisDirEnum, kMaxEntriesPerFetch, &actualFetched, NULL, kFSCatInfoDataSizes | kFSCatInfoNodeFlags, fetchedInfos, fetchedRefs, NULL, NULL); while ((fsErr == noErr) || (fsErr == errFSNoMoreItems)) { ItemCount thisIndex; for (thisIndex = 0; thisIndex < actualFetched; thisIndex++) { // Recurse if it's a folder if (fetchedInfos[thisIndex].nodeFlags & kFSNodeIsDirectoryMask) { totalSize += [self fastFolderSizeAtFSRef:&fetchedRefs[thisIndex]]; } else { // add the size for this item totalSize += fetchedInfos[thisIndex].dataLogicalSize; } } if (fsErr == errFSNoMoreItems) { break; } else { // get more items fsErr = FSGetCatalogInfoBulk(thisDirEnum, kMaxEntriesPerFetch, &actualFetched, NULL, kFSCatInfoDataSizes | kFSCatInfoNodeFlags, fetchedInfos, fetchedRefs, NULL, NULL); } } FSCloseIterator(thisDirEnum); } return totalSize; } |
_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
| References: | |
| >Obtain directory size. (From: Julian <email@hidden>) |
| Home | Archives | Terms/Conditions | Contact | RSS | Lists | About |
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE
Contact Apple | Terms of Use | Privacy Policy
Copyright © 2011 Apple Inc. All rights reserved.