How to Skip Empty Directories in Unrar

This article explains how the unrar utility handles empty directories during extraction, covers the purpose of the -ed switch, and provides practical workarounds for managing or removing empty folders when unpacking RAR archives.

The Short Answer: Does Unrar Have a Skip Switch?

Strictly speaking, unrar does not have a built-in switch to skip the extraction of empty directories.

While many users look for a flag to ignore empty folders during extraction, the official RAR suite only handles empty directories at the time of archive creation using the -ed switch.

Understanding the -ed Switch

The -ed (Exclude Directories / Do not add empty directories) switch belongs to the rar archiving command rather than the unrar extraction command:

rar a -ed archive_name.rar /path/to/files/

When an archive is created with -ed, the compression tool skips storing records for empty directories entirely. Because the folders never exist within the archive, unpacking it with unrar will naturally result in no empty folders on the destination filesystem.

If an existing archive already contains folder records, unrar will recreate them automatically upon extraction, as it reads and reproduces all archived filesystem structures.

Workarounds for Extraction

If you need to extract files without keeping empty directories, you can use the following methods:

1. Extract Files Without Any Directory Structure (-ep)

If your goal is to extract files without creating any folder hierarchy at all (placing all files into the root destination folder), use the -ep switch:

unrar e -ep archive.rar /destination/path/

Note: This flattens the archive structure and strips all subdirectories, not just empty ones.

2. Remove Empty Directories Post-Extraction (Linux / macOS)

To preserve valid non-empty directory structures while removing empty folders after running unrar x archive.rar, run the find command:

find /path/to/extracted/folder -type d -empty -delete

3. Remove Empty Directories Post-Extraction (Windows PowerShell)

On Windows, extract your archive normally and clean up empty directories using PowerShell:

Get-ChildItem -Path "C:\ExtractedFolder" -Recurse -Directory | Where-Object { (Get-ChildItem $_.FullName).Count -eq 0 } | Remove-Item