Command line 7Zip to extract file by specified result path

2

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.

SerG

Posted 2014-02-03T12:55:27.987

Reputation: 422

What you have tried, and what was not working? – Maximus – 2014-02-03T14:33:47.093

@Maximus, I have tried to search in Google and read manuals. And I have drawn a conclusion that there is no way to extract file from an archive so that result file would have specified name (not the same as inside the archive) using only commands of 7zip. – SerG – 2014-02-03T15:04:37.053

Answers

4

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.

Axel Kemper

Posted 2014-02-03T12:55:27.987

Reputation: 2 892

Such 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. – SerG – 2014-02-03T18:35:42.973

Are 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. – Axel Kemper – 2014-02-03T19:04:12.763

I'm not sure, but: this.

– SerG – 2014-02-03T19:08:51.393

1Yes. 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. – Axel Kemper – 2014-02-03T19:16:10.667