Windows – How to determine the actual size on disk for a folder in Windows

disk-spacentfswindowswindows 10

I am either confused as to how Windows calculates the Size on disk value in the properties of a folder, or it is incorrect.

The cluster size on my drive is 4096 byes.

I've created a folder called size-on-disk-test in which I have 64 direct sub-folders and 362,496 files. Each and every file is a text file 3 bytes in size simply containing the text: aaa.

Given each file should in theory use up a single cluster of 4096 bytes, then I should expect to see the file size on disk to read:

number-of-files * cluster-size362,496 * 4096 = 1,484,783,616 (1.4GB).

Instead it reads: 0:

size on disk properties

The Size is, as expected, exactly 3 bytes multiplied by the number of files.

I then made a note of the free space on my disk at the root level and duplicated the folder (this is not a drive with any activity or programs installed, so it should not be affected by other caching etc. on the disk during the test).

According to the check at root level (i.e. clicking properties on my drive in This PC) after duplicating the folder, my free space was reduced by 589,352,960 bytes.

So what is going on? Why is Windows reporting 0 bytes for the size on disk? Why are my calculations wildly off from the reality?

Additionally, does the length of the file name matter? Shouldn't this be taken into account in an accurate calculation? Perhaps the file name length puts a 4095 byte file into two clusters on a 4096 cluster disk? And surely folders take up some allocation space somewhere?

That's a lot of questions for one "question", but I'm hoping someone can just explain to me how the space is taken up including file names, folders and clusters.

Best Answer

The size on disk value is at best only an approximation, this being particularly true when dealing with a complex file system like NTFS. There are many factors that make this far more complicated than would at first appear. Just a few of these factors:

  • Reparse points
  • Compressed files
  • Hard links
  • Sparse files
  • Alternate data streams
  • File and folder Overhead

Small files may fit entirely in the MFT and will not have any data clusters allocated at all. Exactly what size depends on how much space is available in the files MFT entry. That depends on the length of the file name, the space needed for security information, and much more.

The best way to deal with these factors depends on how you want to use the information. There are no clear cut answers as to which way is best so numerous arbitrary decisions had to be made.

Regard the on disk value as only a guide. In some cases, such as with large numbers of very small files, it isn't even close. Real accuracy would only be possible if you could specify all the parameters and even experts would find that hopelessly confusing.

See this article for more information: https://blogs.msdn.microsoft.com/oldnewthing/20041228-00/?p=36863/

Related Question