Computing the size in bytes of all the files in a directory can be achieved with the Unix tool called du. There are two draw backs with that tool under MSYS/MinGW:

  • It is part of MinGW and thus requires the MinGW library.
  • It prints out the size and the name of the directory.

Therefore, I created this tool that computes the size exactly as required by the wpkg control files. There are two advantages:

  • It computes a more realistic size1 for the control file.
  • It is not encumbered by the two disadvantages that du currently has.

Notice that this functionality is also available in wpkg in the form of a command line option: --directory-size.

Usage is very simple:

	dirsize [-opts] <path> ...
	# Nearly equivalent to:  du -ks <path> ...

The available options are:

  • --total (or -c) to only output the grand total of all the directories included on the command line
  • --sizeonly (or -s) only print the byte size, no directory name or block size
  • --blocksize <size> (or -b) to define the size of a block, it can be any number larger than zero
  • --help to print out help information about the command line options
  • --version to print out the current version of the tool

Since version 0.5, this functionality was incorporated in wpkg with the --build and thus it probably renders this tool much less useful.

Since version 0.7, the functionality is availabe in the libdebpackages library.

The --build option automatically generates the Installed-Size field if you don't define it yourself. (You may still need to define the size since what is compressed in the file may only be the tip of the iceberg! Yes! Your script may use the installed data files to generate other files and make the installation grow much larger than what is compressed in the tarball.)

  • 1. The size of each item is rounded up to a specified block size (512 bytes by default, see the --blocksize command line option). Under NTFS it is often 4Kb to 16Kb. The size used by du depends on the system it runs on and is often 512 bytes (although du is capable of adding the space used by the file index.) Now, to get a more realistic size for the target system we should keep the size of each file in bytes. But that could be really large and probably not help that much since we still would have no clue of the size necessary to create the files in the first place (the space used in the directory structures would not be included.)