How does a computer know if a directory exists?

I have heard people saying that a directory takes up no space on a hard drive. If so, how to does a computer know if an empty directory exists


Most operating systems report a file's size based on just its contents, not including the metadata used to track the existence of that file itself.

So an empty file would be reported as "0 bytes" because it holds 0 bytes of data, even though it'll still occupy a non-zero amount of bytes in the filesystem's metadata area (e.g. the MFT or the FAT or the inode table).

The same applies to directories – the entry used to record the directory's existence (and name, location, timestamps, owner, etc.) will indeed use some space within the filesystem's metadata, but if the directory itself is empty then that entry might not point to any data allocation yet.


A Filesystem (of whatever type) stores and indexes metadata (data describing data) that tells it things like what files and directories it contains. A directory is usually just an entry in a list of all directories, indexed for fast reads.