使用 7z 命令行从一个 zip 文件中提取另一个 zip 文件

使用 7z 命令行从一个 zip 文件中提取另一个 zip 文件

我知道这个命令:

7z e [archive.zip]-o[outputdir] [fileFilter]

但是我想要提取的文件位于一个 Zip 中,另一个 Zip 中,例如:

Archivo1.zip\Carpeta1\Archivo2.zip 

我使用这一行,但结果是无法找到档案:

C:\Program Files\7-Zip\7z" x "C:\File 1.zip\Folder 1\File 2.zip" -O"C:\Output folder" "Imagen 1.tif"

我怎样才能工作?

答案1

使用 7z 命令行从一个 zip 文件中提取另一个 zip 文件

以下是我几年前使用 7Zip CLI 脚本执行此操作的方法。从那时起,我不得不使用并调整它一两次以适应需要。

这将提取其他 zip 文件(及其内容)中的所有 zip 文件(及其内容),直到没有其他 zip 文件可供提取,并且基本上从起始 [根] 父 zip 文件递归遍历直到最后一个子 zip 文件及其内容;从所有 zip 和子 zip 文件中提取文件。

我使用这种方法遍历了大约四个级别,出于一些荒谬的原因,一家公司将这样的数据作为标准发送并且无法更改它,但我仍然能够自动执行我所要做的部分。


CLI 7za 批处理脚本

根据需要设置源、目标和工作目录变量,并将文件复制到源目录文件夹中,然后启动它。否则,您可以使用*.zip更改<ParentZipFileName>.zip

:: This script uses the 7zip CLI to extract ZIP file(s) contents in one location to another
:: It then does an XCOPY of extracted ZIP files within the initial extacted files and copies those to a workdir
:: It then deletes ZIP files from source, and extracts the other ZIP files from workdir and loops until complete
:: NOTE that the 7za may need to have the environmental variable set accordinly

SET sourcedir=C:\Source
SET destdir=C:\Dest
SET workdir=C:\Workdir
IF NOT EXIST "%sourcedir%" MD "%sourcedir%"
IF NOT EXIST "destdir%" MD "%destdir%"
IF NOT EXIST "%workdir%" MD "%workdir%"

:unzip
7za -Y e "%sourcedir%" -o"%destdir%" -r
IF EXIST "%workdir%\*.zip" DEL /Q /F "%workdir%\*.zip"
XCOPY /Y /F "%destdir%\*.zip" "%workdir%\"
IF EXIST "%destdir%\*.zip" DEL /Q /F "%destdir%\*.zip"

DIR "%workdir%\*.zip" /A-D                         
ERRORLEVEL 1 GOTO done

:unzip2
7za -Y e "%workdir%" -o"%destdir%" -r
IF EXIST "%workdir%\*.zip" DEL /Q /F "%workdir%\*.zip"
XCOPY /Y /F "%destdir%\*.zip" "%workdir%\"
IF EXIST "%destdir%\*.zip" DEL /Q /F "%destdir%\*.zip"

DIR "%workdir%\*.zip" /A-D                         
IF ERRORLEVEL 1 GOTO done
GOTO unzip2

:done
GOTO EOF

更多资源

相关内容