How to extract all zip files in a folder using winrar with the same name as the zip?

ぃ、小莉子 提交于 2019-12-22 01:36:13

问题


I need to iterate a folder and for each zip file I need to extract it with the name of it. That is, if its test.zip then it should extract to test folder. Similarly it should iterate through my folder and its child folders and extract the things. I wrote the below code but it doesn't extract with the name of the zip. Please advice.

cd %CD%\Setups
for /r %%i in ("*.zip") do (
   echo "%%~fi"
    "C:\Program Files (x86)\WinRAR\WinRAR.exe" a -afzip "%%~dpi" "%%~fi"
    echo came after unzipping
    del /S /Q "%%~fi"
)
exit \b

回答1:


The syntax for extracting zip files with Winrar.exe is like that :

[path\winrar.exe] x [path to zip file] [files to extract, . for all files] [path folder to extract to]

@echo off
set winrar=%ProgramFiles%\WinRAR\WinRAR.exe
CD /D %CD%\Setups
for /f "delims=" %%i in ('Dir /b *.zip') Do ("%Winrar%" x "%%~fi" "%%~dpni\")
pause

Edit on 28/06/2016 @ 13:35

You can also add if you want this switch -ibck to run WinRAR in background :

@echo off
set winrar=%ProgramFiles%\WinRAR\WinRAR.exe
CD /D %CD%\Setups
for /r %%i in ("*.zip") Do ("%Winrar%" x -ibck "%%~fi" "%%~dpni\")
pause


来源:https://stackoverflow.com/questions/38064341/how-to-extract-all-zip-files-in-a-folder-using-winrar-with-the-same-name-as-the

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!