• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 180
  • Last Modified:

Unzip and Unrar in automatic and repetitive way

I will post a question that you may think it is crazy, but if you are a regular user of usenet's alt.binaries.w.ibm-pc.0-day news group then you will understand the reason of my question. However it doesn't matter if you know what I am talking or not; just understand the following - I have a main folder which has many subfolders; each subfolder contains one or more zip files; such zip files when unzipped will extract a rar file; such rar file has the final files I want to access. How can I automate the unzipping and unraring processes ? My operating system is Windows XP. Thanks in advance.
0
asgarcymed
Asked:
asgarcymed
1 Solution
 
Wooky JackCommented:
Are you using Winrar?

Are you saying that after you unzip the files that there are more files within that need to be separately unzipped as well?

0
 
WelkinMazeCommented:
Hi,
You can try to create a BAT file with the following 2 lines:
"C:\Program Files\WinRAR\WinRAR" X -R "D:\Temp\*.zip" "D:\Zip\"
"C:\Program Files\WinRAR\WinRAR" X -R "D:\Zip\*.rar" "D:\Rar\"

You may have to change "C:\Program Files\WinRAR\WinRAR" with the actual location of your WinRAR program as well as some of the other folders.
The 2 above rows will do the following:
If your main folder is D:\Temp\ it and its subfolders will be searched for ZIP files which will be extracted in the D:\Zip\ folder. After that D:\Zip\ folder will be searched for RAR files and they will be extracted in D:\Rar\ folder.

Hope that helps!
0
 
smartjen4uCommented:
yeah what welkinmaze said is right i accept with him ! creating a BAT file will help you surely, i think you should credit welkinmaze, please give a try
0
How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

 
noam_dzCommented:
do a search in windows explorer for ".rar" in your main folder.
windows should know to read the .zip files as directories and fins the ".rar" inside them
then select all files using "ctrl-A".
right click and use winrar commands in the conetext sensitve menu which openes to extart the files.
use winrar 3.51 at least to have winrar extract commands in the context menu.
0
 
WelkinMazeCommented:
noam_dz, this is not an automatic solution. :)
I think that even WinRAR 2.xx have winrar extract commands in the context menu.
0
 
asgarcymedAuthor Commented:
First I want to thank you guys for trying to help me.

thephalanx - it is true - after I unzip the files that there are more files within that need to be separately unrared (each zip file when unzipped will extract a rar file; each rar file has the final files I want to access).

WelkinMaze - the problem I see in creating the bat file is that I have a lot of subfolders, so the bat file will have a lot of lines (and consumes a lot of time to do that).

noam_dz - I have tried what you say but results are disappointing :(
0
 
WelkinMazeCommented:
Nope, the bat files has to be just with these two lines and will do what I've written.
try it!
0
 
WelkinMazeCommented:
"-R" provides that winrar will go through the subfolders
the only problem is that the files will be unzipped/unrared in one folder - the one at the end of the rows in the bat file.
0
 
WelkinMazeCommented:
And about the consumed time, there is no problem at all. The bat file will do it for the minimum possible time.
0
 
asgarcymedAuthor Commented:
WelkinMaze - now I tried your bat file, and as you previewed the problem is that all the files will be unzipped/unrared in one folder. This is very bad because the are files with the same name (inside different subfolders and inside zip and rar files) - so it will overwrite and mix everything :( The solution must preserve the hierarchy "Main Folder"\"Each Subfolder"\"Each Zip"\"Each Rar"\"Each Final file"...
0
 
WelkinMazeCommented:
Is it will be enough if each file is extracted in the directory where it is.
For example if we have 1.zip in folder A then its content to be extracted in it. And if the content is 1.rar then it again to be extracted in A. This way each archive will be extracted in the folder it is and the hierarchy will be "Main Folder"\"Each Subfolder"\"Each Final file"...
0
 
asgarcymedAuthor Commented:
WelkinMaze  - your comment is correct - can you make it real ?
0
 
WelkinMazeCommented:
Ok, again 2 rows.
Change D:\Temp\ with your root folder.
Change C:\Program Files\WinRAR\WinRAR with the path to your winrar.
The option -O+ overwrites existing files with the same name without prompting. You can remove it if you want.

FOR /R "D:\Temp\" %%I IN (.) DO IF EXIST %%I\*.zip "C:\Program Files\WinRAR\WinRAR" X -O+ %%I\*.zip %%I
FOR /R "D:\Temp\" %%J IN (.) DO IF EXIST %%J\*.rar "C:\Program Files\WinRAR\WinRAR" X -O+ %%J\*.rar %%J
0
 
asgarcymedAuthor Commented:
WelkinMaze - now it works perfectly ! Thank you ! I only would like one more thing I didn't say - delete zip and rar files after final extraction is done. Can you update the bat scrip ? Thanks.
0
 
WelkinMazeCommented:
Just add these two lines at the bottom of the bat file:
del /S /Q *.zip
del /S /Q *.rar
0
 
WelkinMazeCommented:
If you use the above be sure to execute the bat file only from the main directory and not from the above level or it will delete zip and rar files outside of the tree you are taling about.
Or better use these two lines instead of the previous ones.
FOR /R "D:\Temp\" %%I IN (.) DO del /Q %%I\*.zip
FOR /R "D:\Temp\" %%I IN (.) DO del /Q %%I\*.rar
0
 
asgarcymedAuthor Commented:
WelkinMaze - the following bat script does not delete zip and rar files after final extraction is done :

FOR /R "D:\Temp\" %%I IN (.) DO IF EXIST %%I\*.zip "C:\Program Files\WinRAR\WinRAR" X -O+ %%I\*.zip %%I
FOR /R "D:\Temp\" %%J IN (.) DO IF EXIST %%J\*.rar "C:\Program Files\WinRAR\WinRAR" X -O+ %%J\*.rar %%J
del /S /Q *.zip
del /S /Q *.rar

Have I misunderstand what you said ?
0
 
WelkinMazeCommented:
Hm, It habe to delete them.
I even tried it just in case.
But try with the second variant that I've posted.
0
 
WelkinMazeCommented:
Or maybe your zip and rar files are read only?
Add /F switch after the del command to delete read only files too.

Here the lines with /F added:
FOR /R "D:\Temp\" %%I IN (.) DO del /F /Q %%I\*.zip
FOR /R "D:\Temp\" %%I IN (.) DO del /F /Q %%I\*.rar
0
 
asgarcymedAuthor Commented:
WelkinMaze - thank you a lot !!

FOR /R "D:\Temp\" %%I IN (.) DO IF EXIST %%I\*.zip "C:\Program Files\WinRAR\WinRAR" X -O+ %%I\*.zip %%I
FOR /R "D:\Temp\" %%J IN (.) DO IF EXIST %%J\*.rar "C:\Program Files\WinRAR\WinRAR" X -O+ %%J\*.rar %%J
FOR /R "D:\Temp\" %%I IN (.) DO del /Q %%I\*.zip
FOR /R "D:\Temp\" %%I IN (.) DO del /Q %%I\*.ra

This is the perfect script I was looking for ! Thank you again !
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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