开发者

Directory Size in Objective C

Since NSFileManager has n开发者_如何学Co capabilities of returning the size of a directory, what would be a suitable & fast method for obtaining directory size?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜