WinRAR Compress/Decompress Buttons (and other)

Note from @Leo:

  • You do not need to use these buttons to compress/decompress RAR files.
  • Opus has built-in support for unpacking RAR archives.
  • If WinRAR is installed, Opus also has built-in support for creating/updating RAR archives via WinRAR without the need for custom buttons.
  • The buttons in this thread can still be useful, for people who want to do things differently and call WinRAR itself, e.g. for more esoteric options WinRAR might have which Opus doesn't.

For how to use the codes in this thread, see here:


Some buttons that I use sometimes.

You can change the parameter x to e (decompression with path that is stored when you created archive)

Extracts files to current directory:

<?xml version="1.0"?>
<button display="both">
	<label>Extract TUTAJ</label>
	<tip>Extracts files to current directory</tip>
	<icon1>C:\Program Files\WinRAR\WinRAR.exe,0</icon1>
	<icon2>C:\Program Files\WinRAR\Uninstall.exe,1</icon2>
	<function type="normal">
		<instruction>cd {sourcepath}</instruction>
		<instruction>"/programfiles\WinRAR\WinRAR.exe" x {file}</instruction>
	</function>
</button>

Extracts file to dir named after the archive (removes extension):

<?xml version="1.0"?>
<button display="both" effect="off">
	<guid>{4BC13510-93C1-4690-9FC5-CE3B08F9D8EE}</guid>
	<label>Extract DIRX</label>
	<tip>Extracts file to dir named a filename (Cut's extension)</tip>
	<icon1>109</icon1>
	<icon2>46</icon2>
	<function type="normal">
		<instruction>cd {sourcepath}</instruction>
		<instruction>"/programfiles\WinRAR\WinRAR.exe" x "{f}" "{o|noext}\"</instruction>
	</function>
</button>

Create RAR archive:

<?xml version="1.0"?>
<button display="both" effect="off" icon_size="large">
	<guid>{77ABC05B-D855-4D15-94E2-4086A0B8B0C6}</guid>
	<label>Add To Archive</label>
	<tip>Create archive RAR</tip>
	<icon1>52</icon1>
	<icon2>46</icon2>
	<function type="normal">
		<instruction>cd {sourcepath}</instruction>
		<instruction>"/programfiles\WinRAR\WinRAR.exe" a {f}</instruction>
	</function>
</button>

Move to RAR archive:

<?xml version="1.0"?>
<button display="both" effect="off" icon_size="large">
	<guid>{80EB4BAD-299B-449E-ACAF-ABFDFFACA7CB}</guid>
	<label>Move to archive</label>
	<tip>move files and folders to an archive</tip>
	<icon1>51</icon1>
	<icon2>46</icon2>
	<function type="normal">
		<instruction>cd {sourcepath}</instruction>
		<instruction>"/programfiles\WinRAR\WinRAR.exe" m {f}.rar {f}</instruction>
	</function>
</button>

Add to ZIP archive:

<?xml version="1.0"?>
<button display="both" effect="off" icon_size="large">
	<guid>{3199946C-7232-4960-AF3B-169631604EF4}</guid>
	<label>Add to ZIP</label>
	<tip>Creating ZIP archive</tip>
	<icon1>102</icon1>
	<icon2>103</icon2>
	<function type="normal">
		<instruction>cd {sourcepath}</instruction>
		<instruction>"/programfiles\WinRAR\WinRAR.exe" a -m5 {file}.zip {file}</instruction>
	</function>
</button>

Extracts ONLY files with given extension:

<?xml version="1.0"?>
<button display="both" effect="off">
	<guid>{B8387E1D-996D-4E55-B765-5B2DF2B04051}</guid>
	<label>Extract *.xxx</label>
	<tip>Extracts ONLY files with gived extension</tip>
	<icon1>C:\Program Files\WinRAR\WinRAR.exe,0</icon1>
	<icon2>C:\Program Files\WinRAR\Uninstall.exe,1</icon2>
	<function type="normal">
		<instruction>cd {sourcepath}</instruction>
		<instruction>"/programfiles\WinRAR\WinRAR.exe" e {file} {Rs|Please, enter a file extension what you need to extract|*.}</instruction>
	</function>
</button>

Warning:

Error handling: The next couple of examples lack error handling and may delete the selected archive(s) even if extraction fails (e.g. due to lack of space). See the separate thread, delete archive ONLY if no error, for a discussion about ways to resolve that while still using WinRAR.exe for extraction.

Extract and delete selected archives (rar, zip, gz, etc. - supported by winrar) to current directory:

  • Creates directory from filename (without archive extension)
  • Silently deletes the archives after decompression (see warning above).
<?xml version="1.0"?>
<button display="icon" effect="off">
	<guid>{EA8B6CDA-4CBF-4536-86D6-3AD4E4D60E5D}</guid>
	<label>Extract DIRX</label>
	<tip>Extract X + delete archives</tip>
	<icon1>109</icon1>
	<icon2>46</icon2>
	<function type="normal">
		<instruction>cd {sourcepath}</instruction>
		<instruction>"/programfiles\WinRAR\WinRAR.exe" x "{f!}" "{o|noext}\"</instruction>
		<instruction>delete ALL FORCE QUIET</instruction>
	</function>
</button>

Extract and delete ALL archives in current folder:

  • Button automatically deselects any selection and select archives handled by WinRAR.
  • Then extracts each to dir created from filename.
  • Finally, deletes the archives. See warning above. Be careful! This button works silently and without any questions!
<?xml version="1.0"?>
<button display="icon" effect="off">
	<guid>{4115B1A2-2338-4D56-AFBF-9F9AD4930843}</guid>
	<label>Extract FOUND DIRX</label>
	<tip>Automatically search for archives in current folder and Extracts it's</tip>
	<icon1>109</icon1>
	<icon2>46</icon2>
	<function type="normal">
		<instruction>cd {sourcepath}</instruction>
		<instruction>select NONE</instruction>
		<instruction>select all *.(zip|rar|tar|tgz|lha|ace|7z|arj|bz2|gz|lzh|z)</instruction>
		<instruction>"/programfiles\WinRAR\WinRAR.exe" x "{f!}" "{o|noext}\"</instruction>
		<instruction>delete ALL FORCE QUIET</instruction>
	</function>
</button>

Note from @Leo:

  • These next two were posted by Zhgwangff in another thread. We've moved them to here to make things a bit tidier.

Add all selected files to RAR in current directory with the name you specify:

<?xml version="1.0"?>
<button backcol="none" display="both" textcol="none">
	<label>Add to RAR</label>
	<tip>Add all selected files to RAR</tip>
	<icon1>#goroot</icon1>
	<function type="normal">
		<instruction>@firstfileonly </instruction>
		<instruction>cd {sourcepath}</instruction>
		<instruction>&quot;/programfiles\WinRAR\WinRAR.exe&quot; a -r &quot;{RS|Name of new RAR file|{o|noext}}.rar&quot; {O} {allfile}</instruction>
	</function>
</button>

Where /programfiles\WinRAR\WinRAR.exe is where you WinRAR.exe is. (If it's in the default place then you won't need to change it.)

You will be prompted for the name of the archive with the default archive name being the same as the first file's name (with rar extension). You can type over the name to use a different one.

You can also change the .rar in the button to .zip to change the type of archive WinRAR creates.

Decompress a RAR or Zip file to directory named with it:

<?xml version="1.0"?>
<button display="both">
	<label>Decompress to new folder</label>
	<tip>Decompress to the Folder named with the file name</tip>
	<icon1>#clippasteshortcut</icon1>
	<function type="normal">
		<instruction>cd {sourcepath}</instruction>
		<instruction>&quot;/programfiles\WinRAR\WinRAR.exe&quot; x &quot;{f}&quot; &quot;{o|noext}\&quot;</instruction>
	</function>
</button>

Sure... just get rid of the ALL FORCE QUIET arguments on the delete command...

Maybe something like this?

<?xml version="1.0"?>
<button display="both" icon_size="large">
	<label>Create SFX</label>
	<tip>Creates a Self-Extracting Archive from selected files and folders</tip>
	<icon1>C:\Program Files\WinRAR\Default.SFX,0</icon1>
	<function type="normal">
		<instruction>cd {sourcepath}</instruction>
		<instruction>&quot;C:\Program Files\WinRAR\WinRAR.exe&quot; a -r -sfx {Rs|Specify name for SFX archive} {O}</instruction>
	</function>
</button>

@LITWINCZUK :
After testing the command above, i think that there's an error when compiling the command line. May be I'm wrong, so if anyone can test it I'll be very thankful.

<?xml version="1.0"?>
<button display="both" effect="off" icon_size="large">
	<guid>{77ABC05B-D855-4D15-94E2-4086A0B8B0C6}</guid>
	<label>Add To Archive</label>
	<tip>Create archive RAR</tip>
	<icon1>52</icon1>
	<icon2>46</icon2>
	<function type="normal">
		<instruction>cd {sourcepath}</instruction>
		<instruction>"C:\Program Files\WinRAR\WinRAR.exe" a {f}</instruction>
	</function>
</button>

As I said before may be I'm wrong, so please could anyone test those for us and post then its feedback.

Well, with the help given from Steje (for Sfx command), I propose this command that asks you to enter the name of the archive.

<?xml version="1.0"?>
<button backcol="none" display="both" textcol="none">
	<label>Créer une archive RAR</label>
	<tip>Ajouter tous les fichiers selectionnés à une archive RAR</tip>
	<icon1>C:\Program Files\WinRAR\WinRAR.exe,0</icon1>
	<icon2>C:\Program Files\WinRAR\Uninstall.exe,1</icon2>
	<function type="normal">
		<instruction>cd {sourcepath}</instruction>
		<instruction>&quot;C:\Program Files\WinRAR\WinRAR.exe&quot; a -r {Rs|Specify name for archive} {O} {allfile} </instruction>
	</function>
</button>

This is turning into a 'help and support' thread, so I expect Nudel or Tanis may come along shortly and break off some of this discussion into a separate topic... but FWIW:

The 'Add To Archive' button above shouldn't ever work as it's written... because the single {f} argument is passing the name of the selected file that you want to add to an archive as the new rar filename... so you get the following error:

! dontfindme.txt: The archive is either in unknown format or damaged

Which makes sense... given the command line usage in this button example... it's sort of missing an argument and trying to overwrite the selected file as if it was already an archive.

Normally. you might want to change the command-line to something like:

"C:\Program Files\WinRAR\WinRAR.exe" a {f|ext=rar} {f}

...which would "work" but would create a new rar file for each selected file if multiple files are selected.

So, I think for ppl that would WANT such a thing, maybe youd like to break this out into two separate buttons... one that runs the command above for an Add each file to a separate Archive, and another based on what TheCoach proposed for a more rounded out generic Add To Archive button... with a small edit or two:

Coach... your command has an unecessary {allfile} argument at the end... the button still "works" as I'd imagine winrar is just ignoring that last arg... but the {O} is giving you everything you need to pass all files.

ADDITIONAL NOTE: If you have LOTS of files selected when you run the command with {O} then it may bomb out with the error in the attached screenshot. This is probably due to a limitation in the length of characters able to be passed through the 'command line'. Version 9 of Opus added a new modifier that helps us get around this... you would modify the command in TheCoachs button to run:

"C:\Program Files\WinRAR\WinRAR.exe" a -r {Rs|Specify name for archive} @{O|filem}

What thois does is use WINRAR's ability to read a text 'listfile' which contains the names of all files to process, rather than passing all file names to the executable directly on the command line. The {O|filem} expression is Opus new modified argument that takes the file names provided by {O} and copies those names to a temporary file with each of the selected file names on a new line. Using {O|file} would place all filenames on a single line in the text file... but it looks like winrar likes one file per line...

Hope this helps... let's see which forum this thread ends up in :slight_smile:. Maybe we break out the 'discussion' into a help and support thread, and get LITWINCZUK and Coach to agree on reposting buttons with some of these considerations taken into account; and which have been tested and are known to work.

@LITWINCZUK: you've been generous in providing your way of doing things to others in the forums and mistook comments of mine in another thread for criticism/sarcasm... hopefully you don't feel the same about this post... just offering my views on things... cheers!

In case of archives in parts (rar, r01, r02...) after extraction, it deletes ONLY the 'rar' file, leaving the others

Hi,

I'm trying to unrar multiple selected files with a button.
The WinRAR context menu did it very well, you select the files, then right click on them, then "Extract Here", and the files start to be unrared in the same thread. (I mean, if you select 3 files and unrar them, you don't have 3 concurrents or 3 successives Winrar windows.)
Winrar is able to decompress them in a row.

I'm trying to reproduce this comportment with a dopus button, here the command I have :

@sync "C:\Program Files\WinRAR\WinRAR.exe" x  {f} "E:\tmp\"

It's almost the same comportment as Winrar, but it is still in 3 different jobs, Dopus throws the first file to Winrar, then Winrar is closed, then dopus sends the second one, and so on...
plus you have this annoying "always on top" windows titled "File function - Directory Opus".

Does someone find a way to make dopus act like Winrar or at least to hide this "on top" window ?

(Aside: There's no need for the @sync there, by the way. It won't have any effect.)

{f} will only turn into a single filename so if you have three files selected (File1.rar, File2.rar and File3.rar, all in C:\ for the sake of argument) then Opus will turn your line into three lines, one for each file:

"C:\Program Files\WinRAR\WinRAR.exe" x C:\File1.rar "E:\tmp"
"C:\Program Files\WinRAR\WinRAR.exe" x C:\File2.rar "E:\tmp"
"C:\Program Files\WinRAR\WinRAR.exe" x C:\file3.rar "E:\tmp"

It should now be obvious why you get three WinRARs appearing, one after the other (or all at once, depending on how WinRAR is written; some programs run in the background and it's up to the program, not Opus).

If you want to only get a single WinRAR then, of course, you need to pass all of the filenames to it at once somehow. There are several ways to do this with Opus, {F} being the usual one. If you use {F} instead of {f} then Opus will list all three files on a single command:

"C:\Program Files\WinRAR\WinRAR.exe" x C:\File1.rar C:\File2.rar C:\File3.rar "E:\tmp"

I don't know whether WinRAR will recognise that command line, though. If it doesn't then you might have to try something different. Opus can also write the list of filenames into a temporary text file, then pass that text file to the program (see here), which works with some things (but is much less common).

I've filed a feature request for a way to disable the progress dialog for certain functions but I think if you make the command run as a single line then it may suppress the progress dialog anyway so try the stuff above and see how you get on.

Use {f|noext} instead of {f}

Can we keep questions about how to use WinRAR to the Coffeeshop forum?

The Buttons & Toolbars forum is meant to be a place where people can find pre-made buttons & toolbars to do useful things without having to wade through unrelated questions and answers.

We aim for this because we ourselves get frustrated when looking for things on other forum-based sites where download threads turn into 50-page monsters with 10 interwoven discussions that get in the way of finding all the information about the download itself. Questions and answers specifically about the download are fine (but may be edited/cleaned up/deleted after a while if they don't look like they'll be useful to other people or can be consolidated into a single informative post/paragraph) but I think we're straying away from that here.

If this was a dedicated WinRAR forum then all of these questions about the WinRAR command-line would have been separate threads/posts and I don't want this thread to turn into a miniature, flattened WinRAR forum. :slight_smile:

Questions about using Opus should go to the Help & Support forum and questions about using other programs (e.g. WinRAR) should go to the support forum/email contact for the program in question, since they should know more about the program than the Opus community, but feel free to also ask in the Coffeeshop if you think someone here might know.

When you find an answer to a question and that answer seems useful to people interested in a download then by all means post the information to the download thread.

I've added two extra WinRAR buttons from Zhgwangff to the bottom of the root post.

I also tidied up the thread from four pages down into a single page by deleting/consolidating a lot of question & answer posts (but keeping the answers themselves where they seemed relevant to the thread).

(If you think it looks like a mess now you should've seen it before! :slight_smile:)

<?xml version="1.0"?>
<button backcol="none" display="both" textcol="none">
   <label>Add to RAR</label>
   <tip>Add all selected files to RAR</tip>
   <icon1>#goroot</icon1>
   <function type="normal">
      <instruction>@firstfileonly </instruction>
      <instruction>cd {sourcepath}</instruction>
      <instruction>&quot;/home\plugins\wrar\WinRAR.exe&quot; a -r {Rs|Name of New file|{o|noext}.rar} {O} {allfile}</instruction>
   </function>
</button>

I found it will not work when you type a name of a new file with space, for example, it will be ok when the new name is "newfile", but when it is "new file", you will got "new.rar" rather than "new file.rar"

It needed quotes around the {Rs}. I've fixed the version in the root post.

I also changed it to use {RS} instead of {Rs}, so the default name is selected to allow you to type over it as soon as the name prompt opens.

I also moved the .rar extension to after the {RS} code so that you don't have to worry about typing over the extension when changing the archive name.

Finally, while I was at it, I changed the path to /programfiles\WinRAR\WinRAR.exe as I figure that'll work out-of-the-box for more people. Hope you don't mind.

Thanks to Leo, it works!

These are all great buttons - thanks for posting them :slight_smile: The only button that I'm trying to create that is not listed here, is to select multiple archives, and extract all of them to one folder that I'm prompted to create (in the source) using digstring. I've fiddled around with the commands, but can't seem to get it working. The button below extracts all the selected archives into separate folders in the source, rather than one folder.

@nodeselect
"C:\Program Files\WinRAR\WinRAR.exe" x "{f}" "{o|noext}\"

I'm trying to modify the above button to either:

  1. Extract all selected archives to one folder that I'm prompted to create (in the source)
  2. Extract all selected archives to a folder that is automatically created using the filename of the first selected file.

If anyone has any ideas to point me in the right direction, please share :slight_smile:

After fiddling around with different commands, I've now got a button that seems to work. When pressed, the user will be prompted to create a folder, which all currently selected archives will be extracted to:

@nodeselect
@runonce:@set dirname={dlgstringS|Enter name|{file$|noext}}
"C:\Program Files\WinRAR\WinRAR.exe" x "{f!}" "{$dirname}\"

I also wrote out another button for 7-zip which does exactly the same thing, just the commands had to be changes slightly:

@nodeselect
@runonce:@set dirname={dlgstringS|Enter name|{file$|noext}}
"D:\Portable\7-ZipPortable\App\7-Zip\7zG.exe" x "{f!}" -o"{$dirname}\"

Both buttons seem to work very well. But I'm not a very proficient coder, so if anyone has any suggestions on how I could tighten it up or go about it in a different way, please give a shout :slight_smile:

How do I use the code for the buttons listed in this post. I see the xml but cannot see where it is used when creating a button.

Jeff

See the sticky post at the top of this Buttons & Toolbars area and also linked in the FAQs.

This question suggests that you are at the bottom of what could be a long and steep learning curve with DOpus. There is plenty of stuff in the various sections and FAQs here to explain what to do.

Meanwhile, until the real experts come in:

  • Right click a toolbar
  • Customise
  • Right click a toolbar again
  • New > New Button
  • Right click on the button
  • Paste code

You can then move the button to somewhere more convenient.

That's just one way to do it.

If the button does not recognise the code as valid, it will not allow you to paste.

Note: It's described in the sticky post Leo referred ht354 to of course - but figured I'd mention here that you don't even need to click "New >>New Button"... if you've copied "button code" from a post here on the forum (complete with the xml and button tags and all that) then simply copying that text from the web browser to your clipboard will let you 'paste' that text to a toolbar while in Customize mode and will actually CREATE the new button for you...

So:

  • Right click a toolbar
  • Click Customise
  • Right click a toolbar again
  • Select Paste
  • Click 'OK' out of Customize mode[/code]

Clicking Insert New->New Button and THEN pasting will result in you having TWO new buttons on your toolbar - one of which will be 'empty' and not do anything :slight_smile:...

THanks for the actual "Make a Button" steps, but the real important thing is what do I do with the "code" that is posted for each button.

When I go in and choose advanced and paste in the code, I get errors.

So what or rather how do I get the supplied code in this thread to act with buttons?

Read the solutions provided to you - they make it quite clear what to do with the xml code, particularly the information given by Leo which will lead you to the FAQ explaining this in great detail.