AnOldSoul
AnOldSoul

Reputation: 4207

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

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

Upvotes: 2

Views: 4842

Answers (1)

Hackoo
Hackoo

Reputation: 18827

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

Upvotes: 3

Related Questions