Create batch file to unzip files in multiple folders

batch-fileunzip

I am trying to create a batch file that searches a folder for zipped files, and unzip them. I want the script to search through all the subfolders in the main folder, and unzip everything it finds. It might be a main folder with several subfolders. Some of the subfolders will contain zipped files, but some will not.

The zipped files will look like "filename.r00", "filename.r01", "filename.r02", and so on. One file will have the name "filename.rar", and it is this file that will need to extracted using 7-zip.

Is it possible to write a batch file that does this, and then deletes all the zip files? I have already installed 7-zip, so if it is possible I would like to use it. If anyone could help me write the batch file, it would be much appreciated!

Thanks!

Best Answer

Here you go

for /r C:\Mainfolder %%a in (filename.r*) do (
7z e %%a -o%%a_Extracted
del %%a /f /q
)

After looking at the switches for 7-Zip this might be faster (untested)

7z x filename.r* -o*_Extracted -r
del filename.r* /f /q

Either way they are extracted to a folder with _Extracted at the end, otherwise it will extract them to a folder with the same name as the archive, and when it deletes the files, it may try and delete the folders too.