开发者

Directory Size in Objective C

开发者 https://www.devze.com 2023-04-07 23:28 出处:网络
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

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

精彩评论

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