title: How can I extract multiple archives to each folder with WinRAR command line?
body: <p>I want to extract ZIP and RAR archives existing in each folder to the respective folder at the command line. Furthermore, I want to delete the original compressed file only if there is no error during decompression. If there is an error on extracting an archive, the archive file name should be written to an error log file and extraction process should continue with the next archive file(s).</p>
  
  <p>I want to move every folder to <code>done</code> folder after the decompression is successful. But folders not containing any archive file should not be moved by the batch file.</p>
  
  <p><strong>Before:</strong></p>
  
  <pre><code>C:
  │
  └─test
      ├─AAAA
      │      XXXX.rar
      │      XXXX.jpg
      │
      ├─BBBB
      │      XXXX.zip
      │      XXXX.jpg
      │
      ├─CCCC(error_file)
      │      XXXX.rar
      │      XXXX.jpg
      │
      ├─DDDD
      │      XXXX.part1.rar
      │      XXXX.part2.rar
      │      XXXX.jpg
      │
      └─EEEE
             XXXX.jpg
  
  </code></pre>
  
  <p><strong>After:</strong></p>
  
  <pre><code>C:
  │
  └─test
      ├─done
      │  │
      │  │
      │  ├─AAAA
      │  │      XXXX.doc
      │  │      XXXX.jpg
      │  │
      │  ├─BBBB
      │  │      XXXX.doc
      │  │      XXXX.jpg
      │  │
      │  └─DDDD
      │         XXXX.doc
      │         XXXX.jpg
      │
      ├─CCCC(error_file)
      │      XXXX.rar
      │      XXXX.jpg
      │
      └─EEEE
             XXXX.jpg
  
  
  </code></pre>
  
  <p>The following code taken from Mofi's answer from initial version of the question and adapted by me did not work.</p>
  
  <pre><code>@echo off
  setlocal EnableExtensions DisableDelayedExpansion
  set "SourceFolder=C:\test"
  set "LogExtract=%SourceFolder%\ExtractionLog.txt"
  set "LogError=%SourceFolder%\ErrorLog.txt"
  set "ArchiveExtracted="
  
  del /Q "%LogExtract%" "%LogError%" 2&gt;nul
  
  for /D %%I in ("%SourceFolder%\*") do (
      if /I not "%%~nxI" == "done" (
          for /F "eol=| delims=" %%J in ('dir "%%I\*.rar" "%%I\*.zip" /A-D-H /B /ON 2^&gt;nul') do (
              if exist "%%I\%%J" (
                  echo Extracting "%%I\%%J" ...
                  "%ProgramFiles%\WinRAR\WinRAR.exe" x -cfg- -logpfu="%LogExtract%" -or -- "%%I\%%J" "%%I\"
                  if errorlevel 1 (
                      set "ArchiveFile=%%I\%%J"
                      &gt;&gt;"%LogError%" call echo Error %%ErrorLevel%% on extracting "%%ArchiveFile%%"
                  ) else (
                      echo %%~nJ| %SystemRoot%\System32\findstr.exe /I /R "\.part[0123456789][0123456789]*$" &gt;nul
                      if errorlevel 1 ( del /F "%%I\%%J" ) else for %%# in ("%%~nJ") do del /F /Q "%%I\%%~n#.part*%%~xJ"
                  )
              )
          )
          if /I not "%%~nxI" == "done" if not exist "%%I\*.rar" if not exist "%%I\*.zip" move /Y "%%I" "%SourceFolder%\done\"
      )
  )
  
  
  endlocal
  </code></pre>