Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

This batch works fine so far, I feel I have come far being that I have only been doing this as a self learning project for a few days with no experience. I am asking if you guys can offer me any suggestions to make it better and help me learn things to push this further. I realize that this is probably easier some other way. I am learning this right now. Any guidance would be appreciated. Thanks

what this does is create all the needed folders for the job to start, then if if for any reason it get stopped and recycles the work space folder to keep it from trying to move and or copy stuff on top of itself, after that it builds a table of contents of sorts of the files and where they are located, it uses these to move the files from where they are to where they need to be, after they reach the compressed folder they are opened, the contents are extracted to the extracted folder, the originals are sent to original folder, after that it keeps recycling the extracted folder until all the archives have been extracted.

@echo off

setlocal
set dirH="%CD%"
set dirW="%CD%\Work Space"
set dirWC="%CD%\Work Space\Compressed"
set dirWE="%CD%\Work Space\Extracted"
set dirWP="%CD%\Work Space\Processed"
set dirS="%CD%\SALVAGE"
set dirO="%CD%\ORIGINAL"
set PATH="%SYSTEMDRIVE%\Program Files\WinRAR\";%path%

IF EXIST %dirW% IF EXIST %dirS% MOVE %dirW% %dirS% >nul
IF EXIST %dirW% RENAME %dirW% "SALVAGE"
IF NOT EXIST %dirW% MD %dirW%
IF EXIST %dirW% IF EXIST %dirS% MOVE %dirS% %dirW% >nul
IF EXIST %dirW% IF NOT EXIST %dirO% MD %dirO%
IF EXIST %dirW% MD %dirWC%
IF EXIST %dirW% MD %dirWE%
IF EXIST %dirW% MD %dirWP%

FOR /f "tokens=2 delims==" %%d IN ('wmic logicaldisk where "drivetype=3" get name     /format:value') DO (FOR %%x IN (%%d) DO (FORFILES /P %%x\ /S /M *.7z /C "cmd /c echo @path"     >> %dirW%\7z.MOVE)) 2>nul
FOR /f "tokens=2 delims==" %%d IN ('wmic logicaldisk where "drivetype=3" get name    /format:value') DO (FOR %%x IN (%%d) DO (FORFILES /P %%x\ /S /M *.rar /C "cmd /c echo @path"   >> %dirW%\RAR.MOVE)) 2>nul
FOR /f "tokens=2 delims==" %%d IN ('wmic logicaldisk where "drivetype=3" get name   /format:value') DO (FOR %%x IN (%%d) DO (FORFILES /P %%x\ /S /M *.zip /C "cmd /c echo @path"  >> %dirW%\ZIP.MOVE)) 2>nul

CD %dirW% & FOR /F "delims=" %%i IN (7Z.MOVE) DO MOVE %%i %dirWC% >nul
CD %dirW% & FOR /F "delims=" %%i IN (RAR.MOVE) DO MOVE %%i %dirWC% >nul
CD %dirW% & FOR /F "delims=" %%i IN (ZIP.MOVE) DO MOVE %%i %dirWC% >nul

CD %dirWC% & FOR %%i IN (*.7z) DO (WinRAR.exe -ibck e -inul -or "%%~ni.7z" %dirWE% &     MOVE "%%~ni.7z" %dirO%) >nul
CD %dirWC% & FOR %%i IN (*.rar) DO (WinRAR.exe -ibck e -inul -or "%%~ni.rar" %dirWE% &     MOVE "%%~ni.rar" %dirO%) >nul
CD %dirWC% & FOR %%i IN (*.zip) DO (WinRAR.exe -ibck e -inul -or "%%~ni.zip" %dirWE% &     MOVE "%%~ni.zip" %dirO%) >nul

:DECOMPRESS
CD %dirWC% & FOR %%i IN (*.7z) DO (WinRAR.exe -ibck e -inul -or "%%~ni.7z" %dirWE% &     MOVE "%%~ni.7z" %dirWP%) >nul
CD %dirWC% & FOR %%i IN (*.rar) DO (WinRAR.exe -ibck e -inul -or "%%~ni.rar" %dirWE% &     MOVE "%%~ni.rar" %dirWP%) >nul
CD %dirWC% & FOR %%i IN (*.zip) DO (WinRAR.exe -ibck e -inul -or "%%~ni.zip" %dirWE% &     MOVE "%%~ni.zip" %dirWP%) >nul

IF EXIST %dirWE%\*.7z MOVE %dirWE%\*.7z >nul & IF EXIST %dirWC%\*.7z goto DECOMPRESS
IF EXIST %dirWE%\*.rar MOVE %dirWE%\*.rar >nul & IF EXIST %dirWC%\*.rar goto DECOMPRESS
IF EXIST %dirWE%\*.zip MOVE %dirWE%\*.zip >nul & IF EXIST %dirWC%\*.zip goto DECOMPRESS

endlocal
pause
share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.