据我所知,7-zip没有命令可以满足您的需求。这是Windows批处理文件脚本,我认为它将执行您想要的操作。它应从命令行运行,以便您可以提供要处理的文件夹树的根的路径。
文件 unzipper.bat
@echo off
setlocal
if "%1"=="" goto Usage
call :Get7zCmd
:: Recurse folder passed in as paramater
for /r %1 %%Z in (*.zip) do (
echo ====
rem Change to the directory of zip file
cd /d "%%~dpZ"
rem Extract all files to current directory
echo %_7zCmd% e "%%~nxZ" -y
rem Delete the zip file
echo del "%%~nxZ"
)
goto End
:Usage
echo.
echo Parses through folder structure starting at the specified path, finding
echo and extracting the contents of all zip files found, and then deletes
echo the zip file.
echo.
echo Usage:
echo %~n0 root-directory-path
echo.
echo For example:
echo.
echo %~n0 "D:\some folder"
:End
goto :EOF
:: ==========================
:: Subroutine Get7zCmd
:: Determines the full path to 7-zip command-line executable from the Windows
:: Registry and sets the variable "_7zCmd" to the result.
:Get7zCmd
set Reg.Key=HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths\7zFM.exe
set Reg.Val=Path
for /F "Tokens=2*" %%A in ('Reg Query "%Reg.Key%" /v "%Reg.Val%" ^| find /I "%Reg.Val%"') do call set PathDirectory=%%B
set _7zCmd="%PathDirectory%%\7z.exe"
exit /b 0
由于脚本总体上是相当激进的,并且可能破坏性,因为它可能会提取大量文件并随后删除许多zip文件,因此我在第12行和第14行禁用了命令,这些命令将以前缀为前缀echo
。这样一来,他们就可以打印出如果echo
没有的话该怎么办。这样,如果出现某种意外问题,您可以先测试脚本,而不会损坏文件系统。
要修改脚本实际执行这些操作,您需要删除echo
这两行中的每一行。当然,适用于任何责任的标准免责声明。