How to Extract Files with Full Paths in 7-Zip
When extracting archives via the command line, maintaining the
original directory hierarchy is essential for keeping files organized as
intended. In 7-Zip, the primary command used to extract files along with
their complete directory structure is the x (eXtract)
command. This guide explains how to use the x command,
contrasts it with the standard extraction command, and covers the
essential switches needed to direct your output to the correct
folder.
The x Command
To extract files and recreate their full directory tree, use the
x command followed by the archive name:
7z x archive.zipUnlike switches that begin with a hyphen (-),
x is a core command in 7-Zip's syntax. It tells the utility
to unpack the archive while strictly respecting and recreating all
internal folder paths stored within the file.
Difference Between x
and e
7-Zip provides two distinct extraction commands:
x(eXtract with full paths): Rebuilds the original folder hierarchy on your disk.e(extract without paths): Flattens the archive contents, placing all extracted files into a single target directory regardless of their internal folder locations.
If your archive contains nested directories, using e
will strip those folders away, whereas x ensures every file
remains in its proper subfolder.
Specifying an Output
Directory with -o
To send the extracted contents to a specific destination folder
rather than the current working directory, use the -o
switch.
Note: In 7-Zip syntax, there must be no
space between the -o flag and the destination
path.
7z x archive.zip -o"C:\Destination\Folder"If the destination path contains spaces, wrap the entire path in
quotation marks directly adjacent to -o.
Common Useful Switches
When running batch scripts or automated extractions, combine the
x command with these practical switches:
-y(Assume Yes): Suppresses interactive prompts and automatically confirms overwriting existing files.7z x archive.zip -o"C:\Target" -y-p(Password): Supplies a password directly from the command line for encrypted archives.7z x secret.7z -p"YourPassword"-aoa(Overwrite All): Overwrites existing files without prompting.-aos(Skip Overwrite): Skips the extraction of any file that already exists in the target location.