7Z and Directory Opus 9

[Note: Opus 10 has 7z support built-in.]

Four buttons for use 7z with DOpus

  1. Add to 7Z (one archive) & Add to 7Z (separate archives)
  2. Extract 7Z & Extract 7Z to ...

You must replace "C:\7-Zip\7z.exe" with appropriate path to your 7z.exe application

<?xml version="1.0"?>
<button backcol="none" display="both" label_pos="right" textcol="none" type="three_button">
<label>Add to 7Z (one archive)</label>
<icon1>#addtozip</icon1>
<button backcol="none" display="both" label_pos="right" textcol="none">
<label>Add to 7Z (one archive)</label>
<icon1>#addtozip</icon1>
<function type="normal">
<instruction>@runonce:C:\7-Zip\7z.exe a -m{dlgchoose|Choose compression method|Ultra=x9+Maximum=x7+Fastest=x1+Fast=x3+Normal=x5+Store=x0} -r "{destpath}{dlgstringS|Archive Name|{file$}.7z}" {allfilepath}</instruction>
</function>
</button>
<button backcol="none" display="both" label_pos="right" textcol="none">
<label>Add to 7Z (separate archives)</label>
<icon1>#addtozip</icon1>
<function type="normal">
<instruction>C:\7-Zip\7z.exe a -m{dlgchoose|Choose compression method|Ultra=x9+Maximum=x7+Fastest=x1+Fast=x3+Normal=x5+Store=x0} -r "{destpath}{dlgstringS|Archive Name|{file$}.7z}" {allfilepath}</instruction>
</function>
</button>
</button>

<?xml version="1.0"?> <button backcol="none" display="both" label_pos="right" textcol="none" type="three_button"> <label>Extract 7Z</label> <icon1>#addtozip</icon1> <button backcol="none" display="both" label_pos="right" textcol="none"> <label>Extract 7Z</label> <icon1>#addtozip</icon1> <function type="normal"> <instruction>@nodeselect </instruction> <instruction>C:\7-Zip\7z.exe x {filepath} -r -o"{destpath$}"</instruction> </function> </button> <button backcol="none" display="both" label_pos="right" textcol="none"> <label>Extract 7Z to...</label> <icon1>#addtozip</icon1> <function type="normal"> <instruction>@nodeselect </instruction> <instruction>C:\7-Zip\7z.exe x {filepath} -r -o"{destpath$}\{dlgstringS|Foldername|{file$|noext}}"</instruction> </function> </button> </button>
Anonymous Administrator

Thanks, and they all work great.

John.

You might want to change C:\7-Zip\7z to C:\7-Zip\7zG so you get a progrress bar instead of a scrolling "DOS box".

Thanks for the Code
but is it possible to make a button for "extract all files in seperate folders" and one for set compressrate without dialoge?

Not sure what you mean by "extract all files in seperate folders"...

If you mean you want to select multiple zip files, click a button and have each zip file extracted into it's own folder, where the folder name is based on the name of the zip file, then I think you need to actually try running the buttons that have been already been posted... The second button does exactly this without any modification.

Regarding your question about the compression button without the dialog. It's really a 7zip command line syntax question more than an 'Opus button' issue. At a glance, the first button runs:

C:\7-Zip\7z.exe a -m{dlgchoose|Choose compression method|Ultra=x9+Maximum=x7+Fastest=x1+Fast=x3+Normal=x5+Store=x0} -r "{destpath}{dlgstringS|Archive Name|{file$}.7z}" {allfilepath}

All of the compressionrate and dialog info comes from the text in bold, so you can just chop out the dialog specific stuff above and replace with a specific compressions rate like -mx9 to compress at ultra level.

Thanks for your detailed answer, but it seems to be to complicate for me :stuck_out_tongue: At Moment when I use the compress button, it compresses not that good as when I compress per context menu, so I think the button doesn't uses the highest compression rate at time. I don't know what I have exactly to do to change that, i've no experience with parameters.

So I'll use 7-Zip again per context menu, but thanks!

A few comments...

<?xml version="1.0"?> <button backcol="none" display="both" icon_size="large" label_pos="right" textcol="none" type="three_button"> <label>Add to 7-Zip Archive</label> <tip>Add to 7-Zip Archive</tip> <icon1>#addtozip</icon1> <button backcol="none" display="both" icon_size="large" label_pos="right" textcol="none"> <label>Add to 7-Zip (single archive)</label> <tip>Add to 7-Zip (single archive)</tip> <icon1>#addtozip</icon1> <function type="normal"> <instruction>&quot;C:\Program Files\7-Zip\7zG.exe&quot; a -mx9 -r &quot;{RS|Archive Name (single archive)|{s|nopaths}.7z}&quot; {F}</instruction> </function> </button> <button backcol="none" display="both" icon_size="large" label_pos="right" textcol="none"> <label>Add to 7-Zip (separate archives)</label> <tip>Add to 7-Zip (separate archives)</tip> <icon1>#addtozip</icon1> <function type="normal"> <instruction>&quot;C:\Program Files\7-Zip\7zG.exe&quot; a -mx9 -r &quot;{RS|Archive Name (separate archives)|{o|noext}.7z}&quot; {f}</instruction> </function> </button> </button>
This Add to 7-Zip Archive button does what the original button above claimed to do, though a bit differently:
[ul][li]it hard codes the Ultra compression mode that sponk sort of asked for (using the -mx9 parameter)[/li]
[li]it creates the archive in the same directory as the selected files... instead of the 'destination' path[/li]
[li]the naming convention of the archives created is more in line with how the 7-zip context menu extension names its archives[/li][/ul]If you liked the nice choice dialog prompting for the compression mode that anoadm used in his original button, then just replace the -mx9 references in the button I've posted with:

-m{dlgchoose|Choose compression method|Ultra=x9+Maximum=x7+Fastest=x1+Fast=x3+Normal=x5+Store=x0}

...which is what I originally suggested sponk to do the reverse of but which I guess he just didn't understand what I was saying :wink:.

Also... The original Add to 7Z (separate archives) button posted above by anoadm actually does NOT work as advertised. Because it uses {allfilepath} like the (one archive) button, it actually creates multiple archives with each archive named after each selected item, but with each archive containing ALL selected items... which I don't think was the intent of the button.

@sponk: There doesn't seem to be any reason why the context menu would compress the files any better than the button, unless of course you did NOT specify Ultra compression mode using the button...

Here are some results using both the button I've posted above (hard set to Ultra compression) and the two different context menu entries from 7-Zip shell extension:

7za457 (Opus Button).7z == 285 KB
7za457 (Context Menu - Add to archive...).7z == 285 KB
7za457 (Context Menu - Add to 7za457.7z).7z == 289 KB

As you can see, the context menu entry that automatically creates the archive without the 7Z dialog is even BIGGER than the one created by the Opus button. not sure what's different there... but this button seems to do the same job or better as the context menu.

'woof

Regarding the "create in separate archives" button... is it possible to do this silently without being prompted for the file name?

For instance, if I have FILE1.TXT, FILE2.TXT, and FILE3.TXT then I just want it to immediately create 3 .7z files with the same names (FILE1.7z, FILE2.7z, file3.7z).

Just replace {RS|Archive Name (separate archives)|{o|noext}.7z} with {o|noext}.7z

@Steje,
I've had 7-Zip buttons on my to do list for quite some time now.
I found some time over the past two days and dug into the command line syntax some.
I then took a good look at this thread and found that you already had it right.
Well, I'm about 10 months late replying to this thread, but I do have couple of things to add here.

 1) Another button can be made that in many cases simplifies the naming process.
    
    In many cases it is useful to name the archive the root of some already existing file or folder name.
    In fact often this file or folder may be located in the Source directory.        
    To this end the control code {filedest$|noext} can be used.
    Select in the Dest either the archive to add to, or the file or folder to name the archive after.
    Select in the Source the files and folders to add to the archive. Press button.
    [code]<?xml version="1.0"?>
Auto add to 7-Zip (single archive) Create or add to a 7zip archive in Source from selected files in Source named root of the first selected file or folder in Dest #addtozip "C:\Program Files\7-Zip\7zG.exe" a -mx9 -r "{filedest$|noext}.7z" {F} [/code]
 2) These buttons could be made better if filem supported unicode.
 
    One of the reasons to use a 7-Zip archive is that it does support unicode.
    The control code {F} will work fine until the line character limit is reached.
    That shouldn't be a problem as long as one is aware of it and organizes files into folders.
    However @{file$|filem} would be a better solution here if only filem supported unicode.
    For what it's worth, in Vista with UAC enabled, the function then requires Admin elevation.
    An @admin is needed.
    
 3) Add -sfx and change 7z to exe to make a self extracting archive.
 
    [code]<?xml version="1.0"?>
Auto 7-zip sfx (single archive) Create a self-extracting 7zip archive in Source from selected files in Source named root of the first selected file or folder in Dest #addtozip "C:\Program Files\7-Zip\7zG.exe" a -sfx -mx9 -r "{filedest$|noext}.exe" {F} [/code]
 4) A Passworded Archive
 
    [code]<?xml version="1.0"?>
Auto 7-Zip Passworded (single archive) Create a passworded 7zip archive in Source from selected files in Source named root of the first selected file or folder in Dest #addtozip "C:\Program Files\7-Zip\7zG.exe" a -mx9 -r "{filedest$|noext}.7z" -p{RS|Enter Password:|Password} -mhe {F} [/code]

I have found a few mistakes here.

[ul]

  1. On Vista 32 neither my buttons or Steje's work properly in a system folder, a drive letter root for instance.

    7-Zip posts a Diagnostic message indicating that access to System Folders contained in the current working folder have been denied even though they were NEVER selected !
    The problem is with 7zG.exe and the syntax both Steje and I used.
    The -r switch is used to recurse subdirectories and is useful when wildcards are used in the command line.
    The documentation goes on to say that the switch -r- disables recurse subdirectories and IS the default for ALL COMMANDS !
    In the prevoius post I made on this thread, I knew from testing that -r wasn't needed here, subdirectories are recursed without the -r switch using the non-wildcard syntax Steje and I both used.
    I thought it would do no harm though, and the documentation clearly recommended it.

Eliminating the -r switch fixes most of this problem on Vista32.
The buttons then work in root folders of drive letters, with the exception of the operating system drive C:.

  1. I made a mistake in reference to filem.

I wrote @{file$|filem}.
Actually, it needs to be @{allfile$|filem} to work properly.

  1. I wrote that when using filem in Vista with UAC enabled, the function then requires Admin elevation.

This is a mistake and is not true.
I did something wrong that I can't repeat now.
[/ul]

So delete the -r switch in these buttons and they should work a little better on Vista.

That'd probably be easy to add to Opus but does 7-Zip (or anything else) understand Unicode text file lists? Maybe it does but it's worth checking first.

Yes, in fact there is the -scs (Set charset for list files) switch.

[code]Syntax
-scs{UTF-8 | WIN | DOS} Default charset is UTF-8.

UTF-8
Unicode UTF-8 character set.
WIN
Default character set of Windows.
DOS
Default DOS (OEM) character set of Windows.

Example
7z a archive.7z @listfile.txt -scsWIN
compresses files from listfile.txt list, that contains list of files in default character set of Windows.[/code]
7zG.exe does currently work using @{allfile$|filem} , but the characters can't be unicode.
There is no need to use the -scsWIN switch .

I made a bunch of files with unicode characters in the filenames.
I used Chineses, Arabic , and a few other languages.
I didtributed these files into a few folders and made a list of the result using Clipboard Copynames.
I saved this list as two UTF-8 textfiles.
One textfile had Windows Endlines and one textfile had Unix Endlines.

7zG.exe successfully created unicode 7-Zip archives from both UTF-8 textfiles.
The answer to your question then is YES !

Another thing that could be useful here is the ability to hide a DOpus File Function progress indicator.
I'm not certain at all as to why it is needed, but in the button examples I posted that use {filedest$}, it obstructs my view of the 7zG progress indicator.
It can be very annoying. :laughing:

{filem} already supports Unicode - if any filenames to be written contain unicode characters it will write the file with a Unicode BOM at the beginning.

Presumably Opus writes utf-16? From what Zippo pasted 7zip only supports utf-8.

But it's open source, so surely someone will add support for it if he asks? :slight_smile:

I added the -scsUTF-8 switch and tried it again.
I get the same error message as without the switch.

[quote]But it's open source, so surely someone will add support for it if he asks? [/quote]Why would they when we can simply use the GUI and context menus that 7-Zip comes with ? :laughing:

I´m using following button:

@NoDeselect
@runonce:F:\Programme\7Zip\7zG.exe a -m{dlgchoose|Choose compression method|Ultra=x9+Maximum=x7+Fastest=x1+Fast=x3+Normal=x5+Store=x0} -r "{sourcepath}{dlgstringS|Archive Name|{file$}.7z}" {allfilepath}

When selecting some files from a directory, all directories will end up in the 7z as well (but at least they´re empty), although they´ve not being selected. Why´s that? It´s ok to include dirs in the 7z in case they´ve been selected, but this makes not much sense.

Another small question, how is the command for a fixed compression ratio?

I tried to figure out, how this button code could work, but i have no idea. Basically it should ask for the name of the 7z, then for a password & 7-Zip it. Any help is appreciated.

"F:\Programme\7Zip\7zG.exe" a -mx9 -r {dlgstring.7z} -p{RS|Enter Password:|Password} -mhe {F}

The .7z has to go outside the {dlgstring} (dlgstring is the same as Rs and uses the same format)