I sometimes download libraries of files of the format:





Too extract these I usually need to go into the item, extract the RAR, then delete all the RAR files, in each folder.

Is there a tool that will recursively go through and do this for me, leaving only the extracted files?

Windows batch script is ok.

5 Answers 5



7-Zip is a free file archiever. It is capable of extracting many formats, including RAR. It can also be executed form the command line, which makes using it in batch scripts possible.

There are many ways to do this. The following are a couple examples:

To extract one file:

7z x item1.rar

To extract all rar files within a directory tree:

dir library\*.rar /s /b > rarlist.txt
for /f %f in (rarlist.txt) do 7z x %f

To delete the files after extraction, add the line

for /f %f in (rarlist.txt) do del %f

Before running such a command, please first make sure that the extraction was successful and that you're removing the correct files by executing a test run with echo instead of del.

Edit 2017-12-29:

Thanks to Casey's input in the comments, it can also be done with PowerShell without the need for an additional file

foreach ($file in (ls *.rar)) { 7z x "$file" -aoa }; rm *.rar
  • 1
    The syntax is actually 7z x filename.rar
    – Casey
    Commented Dec 27, 2017 at 22:34
  • 1
    Additionally, another way you could do this is with PowerShell, and then no intermediate file is needed: foreach ($file in (ls *.rar)) { 7z x "$file" -aoa }; rm *.rar
    – Casey
    Commented Dec 27, 2017 at 22:38
  • 1
    @Casey Thanks! I hadn't yet learned PowerShell back then. I edited the answer
    – Tymric
    Commented Dec 29, 2017 at 14:48
  • but you also need to remove those r01, r02... files for multipart rar files. And you don't need to save a file list since the for loop can already iterate through that
    – phuclv
    Commented Aug 9, 2018 at 12:17
  • @phuclv Good points. If you could write that then it might be simpler to post your own answer with the better script than editing my answer
    – Tymric
    Commented Aug 9, 2018 at 12:21

I would suggest installing python so that you can use the excellent os.walk library function to recurse through the directories and install the patool library to do the unpacking.


I have Total Commander installed on my machines. It has the option to Unpack specific files (with option Unpack each archive to separate subdir) which lets you unpack selected archives in one go.
After that you will have to select the archives again to delete them, so it is not exactly in one step.

Together with its search and Feed to listbox commands you can batch extract archives that are across different folders, which is what you want.
In your example you would search for item?.rar in your /library/ folder.

Total Commander is shareware and costs US$ 44 or € 38


Googling, this appears to be quite a common problem and there are several out of the box solutions for it.

Have a look at this page for a some of them: https://www.raymond.cc/blog/5-free-tools-to-automatically-extract-multiple-rarzip-archives/

I found Unpack Monitor works for me.


What you do is, set it to monitor certain directories (like your download directories) and it will automatically scan for rars, and extract the files/media.

This means when you're downloading, you don't even need to know that you're downloading rars. By the time you look at the folder, everything is already extracted and cleaned up. Very convenient.


Since you have multipart rar files, you'll need to remove those rXX files in addition to the main *.rar ones. The below script will extract all *.rar files and delete all archive files if the decompression was successful

for %%f in (*.rar) do (
    7z x %%f
    if errorlevel 1 (
        echo Error extracting file %%f
    ) else (
        del %%~nf.r*

You can also replace 7z.exe with rar.exe. They use the same syntax

If you use WinRAR GUI version then there's an option to delete the archive after extraction. Just right click on any archive > Extract files... > Advanced and select "Ask for confirmation" or "Always". You can save this as the default option by go back to the General tab and click Save


Quoted from WinRAR's help file

Delete archive

  • Never
  • Do not delete an unpacked archive.
  • Ask for confirmation
  • Ask for user confirmation before deleting an unpacked archive.
  • Always
  • Delete an unpacked archive without a confirmation.

WinRAR deletes an archive only if it had been unpacked without errors and if all archived files were selected to unpack. If you unpack a multivolume archive, all its volumes will be deleted.

Note that you can save the default state of this option with "Save settings" button in General page of extraction dialog and it will also affect command line and context menu extraction commands. Use "Ask for confirmation" and especially "Always" mode with care. Deleting an unpacked archive can cause data loss if used improperly.

Unfortunately this only applies to winrar.exe and not rar.exe but you can still extract files with winrar.exe using x option like above

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.