Command line 7Zip to extract file by specified result path
8,782
You can use the -so
option to write the data to stdout
and redirect to your target file:
Example:
7z e -so xxxx.7z > yyy.txt
The commandline help of version 9.22
beta:
7-Zip [64] 9.22 beta Copyright (c) 1999-2011 Igor Pavlov 2011-04-18
Usage: 7z <command> [<switches>...] <archive_name> [<file_names>...]
[<@listfiles...>]
<Commands>
a: Add files to archive
b: Benchmark
d: Delete files from archive
e: Extract files from archive (without using directory names)
l: List contents of archive
t: Test integrity of archive
u: Update files to archive
x: eXtract files with full paths
<Switches>
-ai[r[-|0]]{@listfile|!wildcard}: Include archives
-ax[r[-|0]]{@listfile|!wildcard}: eXclude archives
-bd: Disable percentage indicator
-i[r[-|0]]{@listfile|!wildcard}: Include filenames
-m{Parameters}: set compression Method
-o{Directory}: set Output directory
-p{Password}: set Password
-r[-|0]: Recurse subdirectories
-scs{UTF-8 | WIN | DOS}: set charset for list files
-sfx[{name}]: Create SFX archive
-si[{name}]: read data from stdin
-slt: show technical information for l (List) command
-so: write data to stdout
-ssc[-]: set sensitive case mode
-ssw: compress shared files
-t{Type}: Set type of archive
-u[-][p#][q#][r#][x#][y#][z#][!newArchiveName]: Update options
-v{Size}[b|k|m|g]: Create volumes
-w[{path}]: assign Work directory. Empty path means a temporary directory
-x[r[-|0]]]{@listfile|!wildcard}: eXclude filenames
-y: assume Yes on all queries
More recent alpha versions (9.30) also do not allow to specify a target filename as direct parameter without redirection.
![SerG](https://i.stack.imgur.com/BcQ4Y.jpg?s=256&g=1)
Author by
SerG
Updated on September 18, 2022Comments
-
SerG almost 2 years
Is it possible to make 7Zip extract one file by name from archive to specified full path (including new filename)?
I've found only:
7zip e <archive> -o<resultDirectory> <filemask>
But it's not what I need.
-
Maximus over 10 yearsWhat you have tried, and what was not working?
-
-
SerG over 10 yearsSuch method leads to redirection the whole informational output too and demands additional filtering. Cause I use 7Zip from c# (as more stable alternative to ionic DotNetZip), I just manipulate folders and file to acheave my goal. Also I seen somwhere, that there is
-rn
option, that allows to rename a file inside the archive, but it's said also have a performance issue. -
Axel Kemper over 10 yearsAre you sure? I've tried it from a cmd.exe box and the resulting file looks fine. It might help to redirect channel 2 (stderr) separately from stdout.
-
SerG over 10 yearsI'm not sure, but: this.
-
Axel Kemper over 10 yearsYes. You get this error if you just use
-so
without actually redirecting stdout to a file. But as soon as you add "> yyy.txt", it works flawlessly. Calling 7z embedded from c# is a different matter beyond your original question.