?
Solved

UnZip/UnRar many files...

Posted on 2005-03-05
8
Medium Priority
?
616 Views
Last Modified: 2008-01-09
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
Comment
Question by:InGearX
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
8 Comments
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 13465193
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
 
LVL 25

Accepted Solution

by:
InteractiveMind earned 2000 total points
ID: 13465198
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
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 13576728
InGearX ... Does this help?

>> IM
0
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
LVL 25

Expert Comment

by:InteractiveMind
ID: 13875304
Thank you.  :-)
0
 

Author Comment

by:InGearX
ID: 13902135
Sorry, I was out, you deserve full credit, thank you very mcuh!
0
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 13902140
That's cool. :-)
Thank you for getting back to me in the end though  ;)
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month12 days, 5 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question