7zip 指令未解壓縮到指定的輸出目錄

7zip 指令未解壓縮到指定的輸出目錄
7z x d:\migration\mongo\mongodb.7z o:f:\data *.* -r

我使用此命令作為批次的一部分,將 7z 檔案的內容從一個磁碟機 (D) 提取到另一個磁碟機 (F)。資料夾結構很重要,因此我使用x遞歸命令。

應該發生的情況是將存檔內容解壓縮為f:\data.

什麼是實際發生的內容正在解壓縮到批次檔的目錄工作目錄 ( f:\migration\) 中。在命令中指定工作目錄 ( -w:) 無效。

如何使我的命令按預期工作?

我在 Windows Server 2012 R2 上使用 7zip x64 9.22b。

編輯:我最初的問題指出資料被提取到兩個同時的位置。事實證明情況並非如此。我的問題已更新以反映這一點。

答案1

我使用的是 7za.exe(命令列版本),但 7z.exe 也是如此。看一下幫助訊息小心:

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

您看到它是如何清楚地提到開關是-o和 了-w嗎?如,有一個連字符在開關之前,但不在命令之前。另外,冒號不是開關本身的一部分。如果是,那麼您應該類似地使用,x:而不僅僅是x使用路徑提取。因此,你對o:<Path>and的奇怪用法w:<Path>是你頭痛的原因。

使用類似的方法遞歸壓縮資料夾並儲存相對路徑:

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

使用以下命令提取到特定目錄:

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

顯然,如果您的資料夾名稱中有空格,請使用雙引號。

答案2

就我而言,它可以在 CMD 中運行,但不能在 Powershell 中運行。引用目標目錄為我解決了這個問題。

以下內容在 CMD 中有效,但在 Powershell 中無效

7z x d:\migration\mongo\mongodb.7z -of:\data *.* -r

以下作品均適用於

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

相關內容