0

I am trying to get the properties for files in a directory, and I have problems with applications. Since applications are in fact directories, their url.resourceValues(forKeys:) for different size-related keys return nil, zero or 96 bytes.

To calculate the application size, I'm doing what I would do with any normal directory, recursively enumerating it using this code: How can I calculate the size of a folder?

However, even though this code is relatively fast, it still takes about 30 seconds to display all the sizes in my Applications directory.

Almost all the file managers I've seen display this information momentarily, so there must be a way to know the total application size without traversing its subdirectory structure, but I cannot find anything that would help me in the docs. What am I missing?

jnpdx
  • 45,847
  • 6
  • 64
  • 94
Const
  • 101
  • 4
  • 1
    The ~30 second wait sounds reasonable. Go to the Finder and Get Info on your /Applications folder. It'll say "Calculating Size" for quite a while before it comes up with a size. Mine's been going almost a minute now. – TyR Oct 12 '21 at 21:59
  • For calculating the size of the folder, it does. But when you go to the Applications folder, your are able to see the size of each individual application instantly. I was wondering, how those are retrieved. – Const Oct 13 '21 at 06:26
  • I was thinking it was just because the individual apps calculate pretty fast, but you're right... even a large complex app like Blender with thousands of sub-files shows up instantly. I do not know how the Finder does this, but my guess is Spotlight. – TyR Oct 13 '21 at 07:43
  • 1
    Are the app sizes showing up instantly after a restart or logout/login? (without calculation the size of the Applications folder first) – Willeke Oct 13 '21 at 09:58
  • @Willeke Thank you! Indeed, they don't. So, I guess they are just being cached after the first calculation? – Const Oct 13 '21 at 11:22
  • you're able to calculate it much faster if you will check it from spotlight cache – Andrew_STOP_RU_WAR_IN_UA Mar 02 '23 at 04:46

0 Answers0