iosnsfilemanagerapfs

How can I get the size of a directory on iOS 10.3 with APFS?


One of the benefits of APFS announced at WWDC 2016 was the ability to get the size of a directory very quickly, instead of having to walk the whole folder structure. The demo given was the Get Info window in Finder not having to asynchronously calculate the size of a directory.

I have an iOS app where I need to display the file size of a directory. Right now I do it recursively, summing up the sizes of all the files in all the subdirectories. But now that APFS has shipped with iOS 10.3, I'd like to take advantage of the new file system to do it much more efficiently. Is there an API for this somewhere? I don't see it referenced in the NSFileManager documentation. Right now I use attributesOfItemAtPath and the NSFileSize key.


Solution

  • I asked this in the APFS lab at WWDC 2018, and it would be done via an API called dirstat_np, but it's currently a private API and not available for public use. It may be offered at some point as a public API but no promises. I'm going to file a radar.