Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 623
  • Last Modified:

UnZip/UnRar many files...

Dear fellow members, could you help me write the following .bat file:

I have a directory with 500+ .zip and .rar files
I want to run a batch file so that all files (each one my one):
1) uncompressed into C:\uncompressed into their very own directories (since some .zip/rar files have flat structure with no directories)
1b) And if any .zip/.rar files are found with, they should be uncompressed as well but in same directory and so on recursively
2) Only if uncompression was successful the source .zip/.rar file is to be moved to C:\delete
3) If uncompression was unsuccessful the file is to be moved into C:\investigate

Machine is Win XP Pro with PowerArchiver and WinRar at our disposal.

Thank you
0
InGearX
Asked:
InGearX
  • 5
1 Solution
 
InteractiveMindCommented:
Hi.

I'm not sure what the command syntax is for using WinRAR and PowerArchive for this. But if you can figure it out, then just alter my code below to do it:

:====8<----[ FileName.bat ]----
@ECHO OFF
TITLE Decompress Utility

REM --------------------------------
SET uncompressDir=c:\uncompress
SET compressedDir=c:\compressedFiles
REM --------------------------------
CLS

ECHO.
ECHO Decompressing Zip files . . .
ECHO.

FOR /F "delims=" %%F in ('dir /s /b "%compressedDir%\*.zip"') do CALL :UNZIP "%%F"

CLS
ECHO.
ECHO Decompressing Rar files . . .
ECHO.

FOR /F "delims=" %%F in ('dir /s /b "%compressedDir%\*.rar"') do CALL :UNRAR "%%F"

TITLE Complete!
CLS
ECHO.
ECHO Complete!
ECHO.
PAUSE>NUL
TITLE Command Prompt
GOTO :EOF

:UNZIP
SET File=%~1
TITLE Decompressing: %~nx1

IF NOT EXIST "%uncompressedDir%\%~n1" @MD "%uncompressedDir%" >NUL

REM ** Change the following line:
UNZIP "%File%" "%uncompressedDir%" >NUL

EXIT /B

:UNRAR
SET File=%~1
TITLE Decompressing: %~nx1

IF NOT EXIST "%uncompressedDir%\%~n1" @MD "%uncompressedDir%" >NUL

REM ** Change the following line:
UNRAR "%File%" "%uncompressedDir%" >NUL

EXIT /B
:====8<----[ FileName.bat ]----


HTH  :)
>> IM
0
 
InteractiveMindCommented:
Sorry; there are two instances of this line:

IF NOT EXIST "%uncompressedDir%\%~n1" @MD "%uncompressedDir%" >NUL

please change them to:

IF NOT EXIST "%uncompressedDir%\%~n1" @MD "%uncompressedDir%\%~n1" >NUL


While I'm here.. All you need to do, is change the two middle lines here:

REM --------------------------------
SET uncompressDir=c:\uncompress
SET compressedDir=c:\compressedFiles
REM --------------------------------

So that they point to the correct directories. You also need to change these two lines:

UNZIP "%File%" "%uncompressedDir%" >NUL
UNRAR "%File%" "%uncompressedDir%" >NUL

So that they actually call the correct programs, and decompress the file "%File%". One more alteration that you need to make, is changing the output directory in both commands from:

"%uncompressedDir%"

to:

"%uncompressedDir%\%~n1"


Then that should work fine  ^_^
Regards.
0
 
InteractiveMindCommented:
InGearX ... Does this help?

>> IM
0
NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

 
InteractiveMindCommented:
Thank you.  :-)
0
 
InGearXAuthor Commented:
Sorry, I was out, you deserve full credit, thank you very mcuh!
0
 
InteractiveMindCommented:
That's cool. :-)
Thank you for getting back to me in the end though  ;)
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now