4
7z x d:\migration\mongo\mongodb.7z o:f:\data *.* -r

I'm using this command as part of a batch to extract the contents of a 7z file from one drive (D) to another (F). The folder structure is important so I'm using the x command with recursion.

What's supposed to happen is the archive contents are decompressed into f:\data.

What's actually happening is the contents are being decompressed into the batch file's directory working directory (f:\migration\). Specifying working directory (-w:) in the command has no effect.

How can I make my command work as intended?

I'm using 7zip x64 9.22b on Windows Server 2012 R2.

Edit: my original question noted that data was being extracted to two simultaneous places. As it turns out this was not the case. My question was updated to reflect this.

  • After the completion of the extraction you have 2 full archive items or was one location being used as the "temps" ? What happens if you specify a working folder too? -W – Psycogeek May 13 '15 at 5:15
  • What OS is this in? there are other things that seem odd about the command shown. "o: " (with a colon there) The documentation shows like " -oF:Data ", then why the wildcard on extract, when your trying to extract all? I don't know myself but for winders OS it did not seem logical. – Psycogeek May 13 '15 at 5:40
  • I'm using Windows Server 2012 R2. After completion I have two full copies. -o: is the argument for specifying the output directory (-o{dir_path}), and from the documentation I've seen the slash is necessary. As for the wildcard, without it no files are extracted for some reason. – Chad Levy May 13 '15 at 5:57
  • I haven't tried specifying a working directory. That's a good idea, I'll give that a try. – Chad Levy May 13 '15 at 5:57
  • Since it's not extracting to two places, you should edit the question title as well to reflect the actual problem. – Karan May 14 '15 at 3:28
7

I'm using 7za.exe (command line version) but the same holds true for 7z.exe. Take a look at the help message carefully:

7-Zip (A) 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18

Usage: 7za <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

You see how it's clearly mentioned that the switches are -o and -w? As in, there's a hyphen preceding the switches but not the commands. Also, the colon is not part of the switch itself. If it was, then you should have similarly used x: instead of just x for extracting with paths. Consequently, your weird usage of o:<Path> and w:<Path> is the reason for your headaches.

Use something like this to compress a folder recursively and store relative paths:

7za a -r Archive.7z C:\InputFolder

Use the following to extract to a specific directory:

7za x -oD:\OutputFolder Archive.7z

Obviously if your folder names have spaces in them use double quotes.

  • 1
    I have been using 7zip for years, and still get tripped up on the commandline parameters every now and then. Very well written answer @Karan – ZachOfAllTrades Mar 13 '18 at 14:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.