Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>- (unsigned long long) folderSizeWithFSRef:(FSRef*)theFileRef { FSIterator thisDirEnum = NULL; unsigned long long totalSize = 0; // Iterate the directory contents, recursing as necessary if (FSOpenIterator(theFileRef, kFSIterateFlat, &amp;thisDirEnum) == noErr) { const ItemCount kMaxEntriesPerFetch = 256; ItemCount actualFetched; FSRef fetchedRefs[kMaxEntriesPerFetch]; FSCatalogInfo fetchedInfos[kMaxEntriesPerFetch]; OSErr fsErr = FSGetCatalogInfoBulk(thisDirEnum, kMaxEntriesPerFetch, &amp;actualFetched, NULL, kFSCatInfoDataSizes | kFSCatInfoRsrcSizes | kFSCatInfoNodeFlags, fetchedInfos, fetchedRefs, NULL, NULL); while ((fsErr == noErr) || (fsErr == errFSNoMoreItems)) { ItemCount thisIndex; for (thisIndex = 0; thisIndex &lt; actualFetched; thisIndex++) { // Recurse if it's a folder if (fetchedInfos[thisIndex].nodeFlags &amp; kFSNodeIsDirectoryMask) { totalSize += [self folderSizeWithFSRef:&amp;fetchedRefs[thisIndex]]; } else { // add the size for this item totalSize += fetchedInfos[thisIndex].dataLogicalSize; totalSize += fetchedInfos[thisIndex].rsrcLogicalSize; } } if (fsErr == errFSNoMoreItems) { break; } else { // get more items fsErr = FSGetCatalogInfoBulk(thisDirEnum, kMaxEntriesPerFetch, &amp;actualFetched, NULL, kFSCatInfoDataSizes | kFSCatInfoRsrcSizes | kFSCatInfoNodeFlags, fetchedInfos, fetchedRefs, NULL, NULL); } } FSCloseIterator(thisDirEnum); } return totalSize; } - (unsigned long long) sizeOfFileWithURL:(NSURL *)aURL { NSDictionary *attr = [[NSFileManager defaultManager] attributesOfItemAtPath:aURL.path error:nil]; if ([attr objectForKey:NSFileType] == NSFileTypeDirectory) { FSRef theFileRef; CFURLGetFSRef((__bridge CFURLRef)aURL, &amp;theFileRef); return [self folderSizeWithFSRef:&amp;theFileRef]; } else { return [[attr objectForKey:NSFileSize] longValue]; } } </code></pre> <p>I also noticed that finder does not divide by 1024, but by 1000 when calculating size. Strange</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload