從批處理檔案中,我需要遞回目錄(和子目錄)并將找到的每個 zip 檔案解壓縮到當前目錄中并洗掉存檔
因此,使用批處理檔案或類似的腳本方法,我想從起始路徑位置遞回所有目錄和子目錄,并且對于找到的每個 zip 檔案,我想將內容解壓縮到與 zip 檔案相同的目錄) 如果成功,我想洗掉 zip 檔案。
我已經很長時間沒有做 bat 檔案了,所以尋找我能得到的任何幫助。
我試過的:
@echo off
echo ******
echo List all zip files using for /f
echo ******
for /f "tokens=*" %%r in ('dir *.* /ad /b') do for %%s in ("%%r\*.zip") do echo ---unzip %%s using output folder %%~dps
echo.
echo ******
echo List all zip files using for /d
echo ******
for /d %%r in (*) do for %%s in ("%%r\*.zip") do echo ---unzip %%s using output folder %%~dps
echo.
echo 1: extract to folders containing zip files - possible overwrites
echo 2: extract each zip to a folder named by the name of the zip file
choice /c 12
if not errorlevel 2 (
for /d %%r in (*) do for %%s in ("%%r\*.zip") do "C:\Program Files\7-Zip\7z.exe" x -y "%%s" -o"%%~dps" && del "%%s"
) else (
rem ------ this is the alternative to extract each zip to its own folder
for /d %%r in (*) do for %%s in ("%%r\*.zip") do (
echo.
echo ******
echo *** Unzipping: %%s to folder: %%~dpns
mkdir "%%~dpns"
"C:\Program Files\7-Zip\7z.exe" x -y "%%s" -o"%%~dpns" && del "%%s"
)
rem ------
)
pause
exit /b
此代碼適用于第一個目錄,但不會進一步遞回到子目錄:
C:\dir1\aaa.zip
c:\dir2\bbb.zip
C:\Dir2\SUB1\AAA.zip <==== my code is not extracting this zip in the subdirectory.
uj5u.com熱心網友回復:
... do (
... 7z x ....
if errorlevel 1 (echo fail %%s) else (echo del %%s)
)
應該解決你的問題。7zip似乎遵循規則并回傳errorlevel0 表示成功,否則回傳非零。if errorlevel對 的運行時值進行操作errorlevel。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/445489.html
