1

Since NSFileManager has no capabilities of returning the size of a directory, what would be a suitable & fast method for obtaining directory size?

Parag Bafna
  • 22,812
  • 8
  • 71
  • 144

2 Answers2

4

There is no fast method: you have to recursively request size of every file in the directory hierarchy.

Don't forget to handle special cases:

  • files (or directories on a Time Machine volume) with multiple hard links: count them only once.
  • special files such as what is found in /dev but can be created everywhere.
  • symbolic links: don't follow them, but count their size.

Depending on your needs, you also have to choose between size of file contents or size of file on disk.

mouviciel
  • 66,855
  • 13
  • 106
  • 140
2

Enumerate all directories inside your folder. "Folder size will be = Sum of All file sizes in side that folder."

Some options:

  1. Programatically doing the same I suggest opendir with readdir_r to enumarate all files -- based on its CPU and Memory.
  2. You can run du command using shell.

There are other options too ... it depend on how you want to do.

Girish Kolari
  • 2,515
  • 2
  • 24
  • 34