How to Set 7-Zip Command Line Output Directory

This article explains how to specify an output directory when extracting archives using the 7-Zip command line interface. You will learn the exact switch required to define the destination path, the syntax rules regarding spacing, and practical command examples demonstrating both flat and full-path extractions to specific folders.

The 7-Zip command line parameter used to specify the output directory for extraction is the -o switch.

Syntax Rule: No Space After the Parameter

A critical syntax requirement of the -o parameter is that there must be no space between the switch and the directory path. Adding a space (such as -o C:\Folder) will cause the command to fail or result in unexpected behavior.

  • Correct: -oC:\TargetFolder or -o"C:\Target Folder"
  • Incorrect: -o C:\TargetFolder

If the specified destination directory does not already exist, 7-Zip will automatically create it during the extraction process.

Choosing the Extraction Command

Before adding the -o switch, choose the appropriate extraction command:

  • x (eXtract with full paths): Preserves the internal folder structure of the archive.
  • e (Extract): Flattens the archive, dumping all files directly into the destination folder without preserving subdirectories.

Practical Examples

1. Extract with full paths to a relative folder:

7z x archive.zip -oExtractedData

This extracts the contents of archive.zip into a folder named ExtractedData inside the current working directory, preserving all subfolders.

2. Extract to an absolute path containing spaces:

7z x archive.7z -o"C:\Users\Username\Documents\My Project"

When your directory path contains spaces, enclose the path in quotation marks directly after the -o flag.

3. Flattened extraction to a specific drive location:

7z e archive.rar -oD:\Backups\Unpacked

This unpacks all files from archive.rar directly into D:\Backups\Unpacked without retaining any original archive directory hierarchy.