1

I've also asked a sibling question for Linux.


In Windows (I just tested):

  • The size of an empty folder is given as 0 bytes
  • The size of an empty file is given as 0 bytes

However, files and folders obviously have names, that must be stored somewhere.

  • Where, roughly, are they stored?
  • Is the maximum memory available to store these data a predefined number or is it dependent on the available space in disk?
  • Does an empty file with a short name take less space than an empty file with a larger name? (or perhaps the data structure in which these names are stored have a fixed byte count for each file, which perhaps fills the remaining bytes with \0?)
  • Does an empty folder with a short name take less space than an empty folder with a larger name?
  • Does an empty folder called foobar take less space, same space or more space than an empty file called foobar?
  • Does an empty file at C:\empty.txt take less space, same space or more space than an empty file at C:\long\nested\path\until\the\empty\file\is\reached\empty.txt?
4

I've also asked a sibling question for Linux.

The difference, if any, is not between Windows and Linux (and are you really going to ask the same question for macOS, for Solaris, etc.?) but between the actual filesystems used to store files on disk.

However, while each OS has its preferred filesystems, FAT32 on Windows still behaves the same as FAT32 on Linux; NTFS on Linux works the same way as NTFS on Windows; and so on. At the same time, various filesystems on the same OS might behave very differently from each other – Ext4 and Btrfs (or FAT32 and NTFS) are miles apart even if they're on the same OS.

The size of an empty file is given as 0 bytes

In all cases, the reported file size is always just the actual contents, not the metadata. Practically all filesystems used nowadays will consider these to be two separate things – if you're imagining that a file consists of its name and data attached together, no, that's usually not how it's done.

The name of a file is often stored in its parent directory (which also allows for hardlinks, i.e. one file having multiple names). So long file names may make the parent directory look larger.

The rest of the file-related metadata might be near the name, or more commonly in a separate area (e.g. inode table).

Is the maximum memory available to store these data a predefined number or is it dependent on the available space in disk?

It varies. Each kind of filesystem can have its own limits – some have fixed maximums, others are limited to certain percentage of the disk, etc.

For example, in FAT, each directory can have a certain maximum number of "directory entries" (with MS-DOS style 8.3 filenames occupying one entry each, but long filenames occupying multiple). This does not apply to NTFS, despite both being on Windows.

In Ext2/Ext4, the entire filesystem is limited to a certain amount of "inodes" (one for each file or directory) which it stores as a list of fixed-size records and the area is always set to a fixed percentage of the disk space. It isn't unheard of to run out of inodes on an Ext4 disk. This does not apply to XFS or Btrfs, which both use dynamic data structures (usually B-trees) and will simply grow on demand.

Does an empty folder with a short name take less space than an empty folder with a larger name? (or perhaps the data structure in which these names are stored have a fixed byte count for each file, which perhaps fills the remaining bytes with \0?)

It varies. For some (most?) filesystems, yes, the name is variable length.

For some other filesystems, only at certain thresholds. Again FAT/exFAT and UFS with their fixed-size directory slots would be examples – if a slot is occupied then it is occupied, no matter if it stores a 1-byte filename padded with null bytes or a 16-byte one.

Does an empty folder called foobar take less space, same space or more space than an empty file called foobar?

Again, it depends on filesystem.

In FAT, if I understand correctly, they would be the same. In NTFS I kind of suspect the folder would be larger, but at this point I am just guessing.

Does an empty file at C:\empty.txt take less space, same space or more space than an empty file at C:\long\nested\path\until\the\empty\file\is\reached\empty.txt?

The file itself, always the same, since the file doesn't know its whole path – the OS finds it by descending through the parent directories. That's probably universal across all filesystems.

Those folders would occupy some non-zero space, though.

4
  • Hello! Sorry to take so long to give feedback. Thank you so much for this answer, it clears it up a lot. Upvoted. However, I still have a question. You said: "The name of a file is often stored in its parent directory" - but then, why do I get a size of 0 bytes for a directory that contains an empty file? – Pedro A Mar 29 at 2:34
  • Still depends on the OS, on the filesystem, on the tool used to count disk space. It is common for some filesystems to always report 0 as directory size, e.g. if the underlying data structure doesn't provide a good definition of "used" space. – user1686 Mar 29 at 14:42
  • Thanks! So it seems to me that from a cross-platform, cross-filesystem point of view, measuring the sizes of directories is quite pointless, since they won't always provide accurate info and vary too much between different filesystems... Do yoy agree? – Pedro A Mar 30 at 3:39
  • 1
    Yes. Due to the different ways they store the information, both the directory structures themselves, and e.g. such things as file extent lists (on extent-based filesystems a "fragmented" file will occupy more metadata space than a "contiguous" one, due to having more extents, despite them adding up to exactly the same data size) the "directory size" is just not a very useful parameter at all. Some operating systems even outright hide it, e.g. if you run dir on Windows Cmd or MS-DOS it won't report directory size at all. – user1686 Mar 30 at 9:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.