WinRAR Compress/Decompress Buttons (and other)

Excellent scripts. Thanks

I have a context menu entry (for all files and folders) that does this action:

"/programfiles\winrar\winrar.exe" a "{dlgstring|New file name|{date|yy-MM-dd} {time|HH.mm}}.rar" {allfile$}

It works pretty well unless it's used for files on my memory stick (pendrive) - WinRAR says "[date] [time].rar: Cannot open [file I selected] \ cannot find this file."
It seems that it's because when used on memory stick, working dir (start in dir) is set incorrectly (not equal to the active lister path).
Setting start in = {sourcepath} for buttons works ok but I cant set "start in" dir for context menu entries.

(Edit May 2011: Most of the examples have been updated to explicitly CD {sourcepath} and this advice would break that change. WinRAR v4 now has a command-line argument that lets you specify the directory it uses for temporary files so you should use that if you need to override its default behaviour. Or just use the built-in RAR support in Opus so you don't have to worry about all this. :slight_smile:)

You can use the CD command to set the working dir. If you find a button you've set the "start in" folder on and click Advanced, it'll show you how to use the CD command, and that should work in a context menu as well.

Thank you, now it works ok.
I supposed there is more nice (robust?) way to do that (like "start in" when editing buttons).

FWIW - the "Start In" field you're talking about in a button editor is only available in the "Simple" button editor dialog... if you switch to the "Advanced" mode you'll find that anything typed into the "Start In" field is ACTUALLY a CD command at the top of the rest of the commands in the button...

For me it's better to Backup the original Archives in case I messed up the extracted Files and need to recreate them.
So I told my Button to do this automatically.

The following creates a new directory named the current Date under my Backup directory and moves the archives there after extracting. This cleans up my working directory without loosing the original files.

You should be able to do this for all Buttons with Extracting function posted here by adding the "@nodeselect" modifier and the two lines creating the Folder and moving the files there (Edit Paths to your needs).

Extract all Archives found in current Folder and Backup the Originals

@nodeselect 
select NONE
select all *.(zip|rar|tar|tgz|lha|ace|7z|arj|bz2|gz|lzh|z)
"/programfiles\WinRAR\WinRAR.exe" x "{f!}" "{o|noext}\"
CreateFolder "E:\Backup\Archives\{date}"
Copy MOVE TO "E:\Backup\Archives\{date}"

Thanks kundal, this works except with archives that have been split into multiple parts. It extracts everything to multiple folders of each part of the archive. Instead of extracting all parts to one folder.

eg.
With these files: "Music.part1.rar" "Music.part2.rar"
The button creates two folders: "Music.part1" "Music.part2" , with the full extraction in each
Instead of just one folder "Music.rar" with the full extraction.

Is there anything I can do to fix this? Or is it a limitation with extracting via the button?

@nodeselect
select NONE
select all *.(zip|rar|tar|tgz|lha|ace|7z|arj|bz2|gz|lzh|z)
"/programfiles\WinRAR\WinRAR.exe" x "{f!}" "{o|noext}\"
CreateFolder "E:\Backup\Archives\{date}"
Copy MOVE TO "E:\Backup\Archives\{date}"

First, the original button has a couple of mistakes:

  • The Select command shouldn't be given the ALL argument unless you want it to select everything. When giving it a pattern, the ALL argument shouldn't be given (although it seems to be ignored in this case, that's just luck).
  • Since the command includes its own explicit quotes around the filenames, @nofilenamequoting should be added to the top to prevent Opus automatically adding (extra) quotes around names that contain spaces.
  • This isn't a mistake, just an improvement: You can get rid of the Select NONE line by adding DESELECTNOMATCH to the main Select line.
  • Another improvement: The last two lines can be combined since the Copy command can be told to create a new folder.

So here's a slightly improved/fixed version of the original:

@nodeselect
@nofilenamequoting
cd {sourcepath}
Select DESELECTNOMATCH *.(zip|rar|tar|tgz|lha|ace|7z|arj|bz2|gz|lzh|z)
"/programfiles\WinRAR\WinRAR.exe" x "{f!}" "{o|noext}\"
Copy MOVE CREATEFOLDER "E:\Backup\Archives\{date}"

Now, building from that, we can make it exclude *.partX.rar (except for *.part1.rar) like this:

@nodeselect
@nofilenamequoting
cd {sourcepath}
Select DESELECTNOMATCH *.(zip|rar|tar|tgz|lha|ace|7z|arj|bz2|gz|lzh|z)
Select DESELECT REGEXP .*\.part[0-9]+\.rar
Select *.part1.rar
"/programfiles\WinRAR\WinRAR.exe" x "{f!}" "{o|noext}\"
Copy MOVE CREATEFOLDER "E:\Backup\Archives\{date}"

And just to say it again, if you only care about zip and rar you don't need to use WinRAR at all since Opus can extract those formats itself. (Support for most of those other formats is coming, too... :slight_smile: Edit May 2011: Opus 10 has that now.)

By the way, using {date} on its own for the destination folder may not make sense for some people, depending on their system locale settings. You can add to the command to specify a date format if it doesn't create the directories you want. (In the UK the format is Day/Month/Year, so that command puts things into paths like E:\Backups\Archives\04\Sep\2010 which I doubt anyone would want. :slight_smile:) The date formatting codes are on the Command Control Codes page near the end of the manual.

Thanks for the help leo. Your fix has it working now. Plus if I repeat the Select DESELECTNOMATCH on the second last line it will select and move all the rars to the 'backup' folder. (As it still only had the part1/s selected so they were only moved).

@nodeselect
@nofilenamequoting
cd {sourcepath}
Select DESELECTNOMATCH *.(zip|rar|tar|tgz|lha|ace|7z|arj|bz2|gz|lzh|z)
Select DESELECT REGEXP .*\.part[0-9]+\.rar
Select *.part1.rar
"/programfiles\WinRAR\WinRAR.exe" x "{f!}" "{o|noext}\"
Select DESELECTNOMATCH *.(zip|rar|tar|tgz|lha|ace|7z|arj|bz2|gz|lzh|z)
Copy MOVE CREATEFOLDER "E:\Backup\Archives\{date}"

Thanks for letting me know that I can use Opus to extract rars, I never realised. I uninstalled Winrar to test it out. After reading some threads I made the buttons that will extract the rars. Do you think this type of thing will be added as a default feature? I think it'd be nice having it there as with the zip options. Also, some icons for the rar files would be great too. :opussanta:

Now, I don't know if I should ask this here, or in a new thread. I have another way that I'd like to extract the rars. I've always wished that Winrar had this type of option...

Ideally, what I would like is to do is extract the rar file/s to a folder by the rar file name. Then have the rar/s moved to that folder (perhaps in a folder titled "RARS").

eg.
Music.part1.rar Music.part2.rar extracts to folder "Music".
Music.part1.rar Music.part2.rar are moved to folder "Music" as well.

OR, and maybe better

Music.part1.rar Music.part2.rar extracts to folder "Music".
Music.part1.rar Music.part2.rar are moved to a new folder called "Music - RARS (extracted)"

-That way, once I am happy the file was extracted without a problem, I can select the folder right below it (with the rars) and delete. It would save me scrolling through my folder to find the rars for it.

I've had a play, but I can't work out how to get all all the multiple parts of a set to be selected. To show you this is where I'm at.

@NODESELECT
SELECT REGEXP {file}\.part[0-9]+\.rar

Please teach me how to put a button.

"add to archive..." command in right click menu,
I want the same function with a above in DOpus toolbar button.

and I want to set a archive password and want to split archives.

therefore , it is useless that compressing start soon without inputing password and split amount.
( If it is posisible to set a regular password and regular split size in advance, it it best)

Please teach me .sorry my poor english.

the first button in the first posting does not work with v. 10
( Extracts files to current directory )

You'll need to add "CD {sourcepath}" to the code with version 10.
Otherwise the files are extracted to "C:\Windows\System32".

No its not working
It says "No archives found"

I've updated most of the examples in this thread to include the "cd {sourcepath}" lines required by Opus 10. Haven't tested the buttons so let me know if I've broken anything.

And let me re-iterate that you do not need to use these buttons as Opus has built-in support for RAR.

I can't get the third one, "Create archive RAR" to work.

Edit: OK. I see how it works, now.
It adds all files in the folder to the selected archive. "Create archive RAR" is not a very good description of what it does.

But what about a button for creating a new archive?

If you have Opus 10, just use this (no need to complicate things by calling WinRAR.exe directly):

Copy ARCHIVE=.rar HERE

If you have Opus 10, just use this (no need to complicate things by calling WinRAR.exe directly):

Copy ARCHIVE=.rar HERE

How do I paste that?

Edit the existing button and replace its command with that one.


I am not sure what this is supposed to do, but it is greyed out unless I click on a file.
So I click on a file and press the button, and I get this error:

It then produces this double extension file:
Filename.rar.zip

BTW. I really only want a button to create a new archive.

You want to create a new empty archive? The command for that is:

CreateFolder ARCHIVE=.rar

Are you using Opus 9 or Opus 10? The commands in my posts from today only work in Opus 10.

Also make sure RAR is enabled in Preferences / Zip & Other Archives / Archive and VFS Plugins.

Also make sure .rar is NOT included Preferences / Zip & Other Archives / Zip Files: Zip Extensions. (.rar is not a Zip extension but some people added it to that list for some reason.)