Unzip or Unrar files with Batch file?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
ivar75
Posts: 5
Joined: 11 Apr 2012 05:31

Unzip or Unrar files with Batch file?

#1 Post by ivar75 » 12 Apr 2012 05:29

Hi Friends,

Can I unzip or unrar multiple files by creating a batch file?

Plz help me

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Unzip or Unrar files with Batch file?

#2 Post by foxidrive » 12 Apr 2012 08:28

Yes, if you use command line unzip and unrar tools.

You need to give more information about where the files currently exist and where the extracted files will go.

Do you know the unzip and unrar command line switches?

Fawers
Posts: 187
Joined: 08 Apr 2012 17:11
Contact:

Re: Unzip or Unrar files with Batch file?

#3 Post by Fawers » 12 Apr 2012 09:05

There should be a file called "rar.exe" in your %programfiles%\WinRAR folder.
CD (or PUSHD) your DOS window into it and type

Code: Select all

rar.exe /?

It'll return all the command line parameters to you.

Done that, you shall then tell us what exactly you want in your batch file.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Unzip or Unrar files with Batch file?

#4 Post by foxidrive » 12 Apr 2012 09:36

Fawers, Winrar will only be there if the user has installed it, right?

Fawers
Posts: 187
Joined: 08 Apr 2012 17:11
Contact:

Re: Unzip or Unrar files with Batch file?

#5 Post by Fawers » 12 Apr 2012 09:39

foxidrive wrote:Fawers, Winrar will only be there if the user has installed it, right?

I said that assuming he's got it.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Unzip or Unrar files with Batch file?

#6 Post by foxidrive » 12 Apr 2012 09:58

Fawers wrote:
foxidrive wrote:Fawers, Winrar will only be there if the user has installed it, right?

I said that assuming he's got it.


Where did you say that? :D

Fawers
Posts: 187
Joined: 08 Apr 2012 17:11
Contact:

Re: Unzip or Unrar files with Batch file?

#7 Post by Fawers » 12 Apr 2012 10:06

foxidrive wrote:
Fawers wrote:
foxidrive wrote:Fawers, Winrar will only be there if the user has installed it, right?

I said that assuming he's got it.


Where did you say that? :D


I said that:
There should be a file called "rar.exe" in your %programfiles%\WinRAR folder.
CD (or PUSHD) (...)

assuming he has got WinRAR installed already.

to assume (verb)
suppose to be the case, without proof


http://oxforddictionaries.com/definitio ... s&q=assume

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Unzip or Unrar files with Batch file?

#8 Post by foxidrive » 12 Apr 2012 10:17

Fawers wrote:There should be a file called "rar.exe" in your %programfiles%\WinRAR folder.
CD (or PUSHD) your DOS window into it and type

Code: Select all

rar.exe /?

It'll return all the command line parameters to you.

Done that, you shall then tell us what exactly you want in your batch file.


If this is English 101 then please tell me where you used the word 'assuming'?

Fawers
Posts: 187
Joined: 08 Apr 2012 17:11
Contact:

Re: Unzip or Unrar files with Batch file?

#9 Post by Fawers » 12 Apr 2012 10:30

foxidrive wrote:
Fawers wrote:There should be a file called "rar.exe" in your %programfiles%\WinRAR folder.
CD (or PUSHD) your DOS window into it and type

Code: Select all

rar.exe /?

It'll return all the command line parameters to you.

Done that, you shall then tell us what exactly you want in your batch file.


If this is English 101 then please tell me where you used the word 'assuming'?


Oh god.

Look, mate,
I really don't want to flood - or keep flooding - the forum like this.
It is not my fault if your individual understanding skills are not good.
I don't have to say that I'm assuming something1 = something2 for people to understand that what I am doing is, in fact, assuming.

Besides, none of us is helping our fellow here with his problem.


But ok. Assuming our fellow has got WinRAR installed on his HD, and assuming he has checked "rar.exe" command line parameters already, what would the next step be? :wink:

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Unzip or Unrar files with Batch file?

#10 Post by foxidrive » 12 Apr 2012 10:52

You can help him mate.



You were so anal when all you had to say was 'Oh, I wasn't very clear, was I?.

Now that you have a dictionary, look up the word 'ego'. Try and reduce yours a few notches.

Fawers
Posts: 187
Joined: 08 Apr 2012 17:11
Contact:

Re: Unzip or Unrar files with Batch file?

#11 Post by Fawers » 12 Apr 2012 11:00

Tested:

Code: Select all

@echo off
set rarpath=
::rarpath should contain the full - or short - path of rar.exe file inside WinRAR folder
::assuming you've got WinRAR, of course
::place this batch file in the same folder as your .rar files
::files will be extracted into this same folder
::WinRAR command line works well with .rar files, but not with .zip files

:EXTRACT
if exist *.rar (
  "%rarpath%" e *.rar
  >nul pause
) else (
  for %%d in ("%cd%") do echo No .rar files were found in "%%~nd".
  )

Last edited by Fawers on 12 Apr 2012 11:18, edited 3 times in total.

Fawers
Posts: 187
Joined: 08 Apr 2012 17:11
Contact:

Re: Unzip or Unrar files with Batch file?

#12 Post by Fawers » 12 Apr 2012 11:06

foxidrive wrote:You were so anal when all you had to say was 'Oh, I wasn't very clear, was I?.

foxidrive wrote:If this is English 101 then please tell me where you used the word 'assuming'?

All I had to say was that. And all you had to say was, "Oh, you assumed it, didn't you?".
Oh, the irony.
Was all that really necessary?

I'm finished with the flooding.

Fawers
Posts: 187
Joined: 08 Apr 2012 17:11
Contact:

Re: Unzip or Unrar files with Batch file?

#13 Post by Fawers » 12 Apr 2012 19:03

I figured a way to unzip files with batch.

On my previous code, I couldn't help but notice that it wouldn't unzip files; it will only unrar them.

Do you have 7zip? If you don't, look forward to downloading it, for it has too a command line based file named "7z.exe".

I tested it and it works both with .7z and .zip files. In essence, we can have one batch script to extract .7z, .rar and .zip files.

I'll start writing the code, and will post it here later.
7-Zip download page

Liviu
Expert
Posts: 470
Joined: 13 Jan 2012 21:24

Re: Unzip or Unrar files with Batch file?

#14 Post by Liviu » 12 Apr 2012 20:26

Fawers wrote:Was all that really necessary?

It's customary to mention dependencies on external packages, even more so in the case of "paid for" ones such as WinRAR.

FWIW there is also the completely free and standalone unrar.exe (http://www.rarlab.com/rar_add.htm) which requires no money, no installation, and has its source code available.

Fawers wrote:Do you have 7zip? If you don't, look forward to downloading it, for it has too a command line based file named "7z.exe".

7z.exe requires 7z.dll too. The self-contained 7za.exe (in the 'extra' package at http://sourceforge.net/projects/sevenzi ... -Zip/9.22/) supports fewer formats natively, including 7z and zip, but not rar.

Liviu

Fawers
Posts: 187
Joined: 08 Apr 2012 17:11
Contact:

Re: Unzip or Unrar files with Batch file?

#15 Post by Fawers » 12 Apr 2012 20:53

Liviu wrote:FWIW there is also the completely free and standalone unrar.exe (http://www.rarlab.com/rar_add.htm) which requires no money, no installation, and has its source code available.

But does it support command line operations?

7z.exe requires 7z.dll too. The self-contained 7za.exe (in the 'extra' package at http://sourceforge.net/projects/sevenzi ... -Zip/9.22/) supports fewer formats natively, including 7z and zip, but not rar.

I think the standard 7zip installation file comes with 7z.dll already. At least I have it here in 7-Zip folder, and I can't remember of downloading any additional patch/update. I don't have 7za.exe, though.

Post Reply