Since NSFileManager has no capabilities of returning the size of a directory, what would be a suitable & fast method for obtaining directory size?
Asked
Active
Viewed 1,006 times
2 Answers
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:
- Programatically doing the same I suggest opendir with readdir_r to enumarate all files -- based on its CPU and Memory.
- 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
-
Is du have different behavior on different version of MAC OSX? – Parag Bafna Sep 29 '11 at 06:46
-
I never find a difference ... even if you find any deference you can build du from open source and keep it with you app to use in all OS – Girish Kolari Sep 29 '11 at 08:01