How Unrar Extracts Empty Directories

When extracting RAR archives, maintaining the original folder hierarchy is often critical for data integrity and application structure. This article explains how the unrar command-line utility handles empty directories during the extraction process, the behavioral differences between primary extraction commands, and the role archive metadata plays in whether empty folders are recreated on your system.

Folder Metadata in RAR Archives

The RAR format treats directories as distinct entries within the archive file table, separate from the files they contain. When a folder is archived—even if it contains no files—the archiving tool creates a specific directory record that stores the folder's name, path, attributes, and timestamps. Because this metadata exists independently of file payloads, unrar has the necessary information to recreate empty directories upon extraction.

Full Path Extraction: unrar x

To extract empty directories, you must use the full-path extraction command:

unrar x archive.rar

The x switch instructs unrar to unpack the archive while strictly preserving the internal directory hierarchy. When processing the archive stream, unrar reads the directory records and creates each folder on the target file system, regardless of whether any files reside inside it. Furthermore, unrar will attempt to restore the original timestamps and file permissions associated with the empty directory, provided the user running the command has sufficient system privileges.

Flattened Extraction: unrar e

If you use the basic extract command instead:

unrar e archive.rar

unrar extracts all files directly into the current working directory or a specified target directory, stripping away all subfolder paths. Under this mode, unrar completely ignores directory records that do not contain files. As a result, empty directories are omitted entirely and will not be created on the destination file system.

Exceptions and Archive Creation Caveats

While unrar x naturally restores empty folders, there are scenarios where empty directories will not appear:

  • Excluded Paths During Compression: If the archive was created using compression options that intentionally exclude empty directories (such as specific flags in GUI tools or custom scripts), the directory metadata was never written to the archive. unrar cannot reconstruct directories that do not exist in the archive headers.
  • File System Permissions: If the user executing unrar lacks write permissions for the destination path, the utility will fail to create the directory and will return a permission-denied error.
  • Corrupted Archive Headers: If the directory header within the RAR file is damaged, unrar may skip the folder entry or terminate extraction with a checksum error.