Swift: Quickly get the size of a folder

Viewed 731

here on SO are a lot of topics about getting the size of a folder programatically in Swift. All accepted answers suggest to use the FileManager and then enumerate over all files to and sum the size of all files.

However, I was asking myself if there is a faster way to get the size of a folder? Enumerating over all files can take a very long time and when I use the Finder and right-click a folder and select "Information", the size is displayed instantly.

Is the size a "secret" property of a folder that is only available to the OS? Does the operating system index all folders/files in the background?

When I do the same thing in Windows, the subfolders and files are also enumerated.

Why do I ask this question? Because I am developing an app that is processing files of a directory and I would like to show some sort of progress bar. But If I have to enumerate all files twice (once to get the total count and once to actually process them), is not very good.

Regards, Sascha

0 Answers
Related