Button to Create/Extract DIS Files for Editing

Since I've been creating a lot of personalized icon sets, it seemed like a good idea to create a button for creating and extracting them.

It's set up as a three-button, where left click creates ZIP files from any selected folders, deletes the original folders, and renames any .zip files in the selected directory to .dis:

Copy ZIP=single HERE @nodeselect Delete QUIET Select PATTERN="(.+).zip" REGEXP Rename PATTERN="(.+).zip" TO="\1.dis" REGEXP AUTORENAME TYPE=files

The right-click renames selected .dis files to .zip, extracts them, and deletes the original .dis files:

Rename PATTERN="(.+).(dis|DIS)" TO="\1.zip" REGEXP AUTORENAME TYPE=files @nodeselect Copy EXTRACT=sub HERE Delete QUIET

Is there a better way to go abou this?

The selection and deletion commands seem a little awkward to me, and the left-click doesn't work exactly as I'd like. It works perfectly with a single file, but if I have multiple folders selected, I get one (proper) .dis file and two (unrenamed) .zip files. Seems like I've got some bad syntax in there somewhere.

Can anyone clue me in or suggest a better approach?

These should work better.

Creation:

@nofilenamequoting @firstfileonly @set dirname = {file$} Copy "{$dirname}" ZIP=single HERE Rename "{$dirname}.zip" TO "{$dirname}.dis" Delete "{$dirname}" QUIET

Extraction:

@nofilenamequoting @firstfileonly @set dirname = {file$|noext} Rename "{$dirname}.dis" TO "{$dirname}.zip" Copy "{$dirname}.zip" EXTRACT=sub HERE Delete "{$dirname}.zip" QUIET

If you want you can simplify the extraction, removing the need for a special button entirely, by adding .dis to the list of recognised Zip extensions in Preferences -> Zip Files. Then you'll also be able to double-click .dis files to enter them.

By the way, be aware that the Delete command will still be run if the Zip command fails. Zip-and-delete buttons are convenient but slightly dangerous if you don't have a backup of the data. So long as you've got Opus configured to use the recycle bin you should be okay. If you've turned off the recycle bin, though, you might want to make the command move the folder/archive to a backup/temp location instead of deleting it, just in case the zip/unzip fails. It's unlikely to fail but you don't want to lose your work if it does!

Can't believe I never said "thanks," Leo! :blush:

These have worked like a charm in most cases — but I've noticed they fail when a file name contains spaces. I get this error:

Is there anything I can do to avoid that? I've tried using quotes in assigning the {$dirname} variable:

@set dirname = "{file$|noext}"

... but that doesn't seem to work.

:question:

Oops, my fault. It should work if you add @nofilenamequoting, which I've added to the original post above. Give that a try.

(Since I had already put the quotes into the commands, Opus needs to be told not to add extra quotes when things contain spaces.)

Rock on! Adding @nofilenamequoting makes the buttons compatible with all my long, spaced-out file names. :smiley:

Hmmm — it looks like I may have a different problem with a related button, however. I have another set of buttons for extracting and creating .CBR (Comic Book RAR) files. (They're just renamed RAR archives.) The extract button works fine with the updates:

@nofilenamequoting @firstfileonly @set dirname = {file$|noext} Rename "{$dirname}.cbr" TO "{$dirname}.rar" Select "{$dirname}.rar" "/programfiles/WinRAR/WinRAR.exe" x "{f}" "{o|noext}\" Delete "{$dirname}.rar" QUIET Select "{$dirname}"

... although, come to think of it, that last Select command doesn't seem to work. :question:

But, for some reason, my create button wants to add everything in the directory to my RAR file before renaming it.

@nofilenamequoting @firstfileonly @set dirname = {file$} Select {$dirname} "/programfiles/WinRAR/WinRAR.exe" a -r "{$dirname}.rar" Rename "{$dirname}.rar" TO "{$dirname}.cbr" Delete "{$dirname}" QUIET Select "{$dirname}.cbr"

Sorry to be a pest, but any insights are certainly welcome.

And if you're feeling particularly generous: Is there a way to set these buttons up so they would operate on several selected files (running through the full set of commands each time before moving on to the next file)?

Every effort I've made to do that has run into one stumbling block or another. I'm hoping there may be a way to define a whole set of commands as some type of function and then execute that function on selected files in a "foreach"-style manner — but, as far as I can tell with my limited experience, Opus commands just don't work that way.

So - there are a few issues here...

1.) I don't use WinRAR - and I 'think" you're saying you only want it to add the "selected" files to the new archive - as opposed to it currently adding "everything in the directory"? If that's the case, then I think you're using the WinRAR cli a bit incorrectly by not having some sort of filespec appear at the end of the command after the new archive name you want to create. From the WinRAR help:

[quote="RARLabs"]Notes
a) If neither files nor listfiles are specified, then . is implied and WinRAR will process all files[/quote]
From there, I'd humbly suggest you consider a revised button something like:

@nofilenamequoting @firstfileonly "/programfiles/WinRAR/WinRAR.exe" a -r "{file$|noext}.cbr" @{allfilepath$|filem} Delete ALL QUIET
*Note: You don't need to bother with these "rename" acrobatics... you can specify the desired filename (and as shown below - "location" as well) as part of the creation of the archive (with both WinRAR and with Opus native ZIP creation).

From there... I'd also (even more humbly) suggest that (depending on your ACTUAL situation) maybe a further modified command like THIS might be useful?

@nofilenamequoting @firstfileonly @set $dir={s|noterm} "/programfiles/WinRAR/WinRAR.exe" a -r -ep1 "{s|..}{RS|Confirm new CBR filename...|{s|nopath|noterm}}.cbr" @{allfilepath$|filem} Go UP Delete "{$dir}"
This button will archive the currently selected files to a new CBR file located in the PARENT folder of your current working directory, and then delete the directory. It also uses the current directory as the name for the new CBR file, but shows it to you in a dialog that let's you change the name if you want - or just hit or the OK button to accept what is shown to you... Not sure that's really something you would want; but it seemed a bit odd to me that you'd actually want to create your new CBR file based on the name of the first image file in the comic... And again, this is just an example of something "I" might find a bit more on point with how "I'd" do it... as opposed to just tweaking your current button to do what it "seems" like you want to do.

I have some other thoughts but am about to arrive at my train stop... more later...

Back for another round...

2.) You asked about running commands in series, one file at a time... not sure if that question was specifically in reference to what you're trying to do with these buttons here in this topic. You might want to start a new topic if it's something you're curious about in a "general" sense. There are some things you can do, but there are also scenarios with different types of commands that make it so that things don't always work the way you might expect...

As an aside (back to other things mentioned earlier in this thread) - and at the risk of trying to fix what ain't broke... you can just add certain extensions (like DIS, CBZ, and any other "zip" file format with different extensions) to the list of Extensions under Prefs->ZIP Files->Settings... and then all of the Opus ZIP commands work against them without having to do all the rename/delete stuff. For instance, I've got "cbz;.dis;.dlt;.dps;.exe;.ocb;.u3p;.zip" listed as my ZIP extensions... I've also then created an "Archives.Opus" Opus File Type Group in the FileType Editor - with those same extensions assigned (and .cbr files as well). I've then got various Events, Context Menu actions, and Drop Menu actions set for that File Type Group to either just double-click and browse the cbz (and cbr) files as folders without even extracting - OR - to extract them to a drop target folder or new folder in the drop folder (with the new folder named based on the filename), etc, etc, etc...

Anyhow, again - if the method you've got "works" this is just another way of doing it without having to copy/rename/delete, etc...

Opus can also extract every .cbr file I've ever come across with the native RAR plugin (i.e. no need to use WinRAR for that - unless you've come across more advanced cbr's than I have with encryption or some other RAR specific attribute that Opus might not support, like some advanced encryption password or something). You specifically should NOT add .cbr to the list of ZIP File extensions I mentioned above - as it's not a "zip" file. Instead, to get Opus to use the RAR plugin to make commands like Copy EXTRACT HERE and Copy EXTRACT=sub HERE work, you need to do a "similar" sort of thing as mentioned above - except for the RAR plugin, it's in a different spot. Goto Settings->VFS Plugins->RAR->Configure... and a dialog pops up with an "Extensions" field in which you can enter a semi-colon delimited list of file extensions to be treated as RAR files (my list is just .001;.cbr ;.rar).

Again - not necessarily what you were asking about - but relevant I think to working with zip and rar archive files with different extensions than the "norm"...

*Note: in my post above, in the second ("even more humbly") suggested button I showed - I also used an additional WinRAR switch that I neglected to call out and explain... -ep1 makes it so that any files you archive don't get added with their "full paths" from the root drive - which in a quick test showed otherwise happens by default... i.e if my working directory was something like D:!downloads\comics\The_Death_of_Dracula__2010\Death of Dracula (2010) - then that entire folder path also get's created in the new rar/cbr file. That's alot of extra double-clicking into folders if you just want to browse the new file later. I think WinRAR has default compression "profiles" that maybe you might change to make this the default behavior... just thought I'd mention it.

OK - I'm DONE...! Back to work... :frowning:

Steje, you are a marvel! All that help and insight while you were on the train (and I like to imagine you on the way home from a tough day at the office, to boot). Please — check that humility at the door and feel free to suggest boldly wherever I'm concerned. :laughing:

You nailed it. My client line skills are pitiful, and I was assuming WinRAR would perform its operations on the selected files merely because I'd selected them. (In my defense, I'd probably been playing around with Opus commands and forgot I was passing values to RAR for it to operate on.)

Another instance of your instincts being spot-on! My original button had included this syntax:

"/programfiles/WinRAR/WinRAR.exe" a -r "{RS|Name of new CBR file:|{$dirname}}.cbr"

... but I'd temporarily trimmed it out while I was trying to find the gremlin (the missing target file parameter). With your suggestions, it's now:

"/programfiles/WinRAR/WinRAR.exe" a -r "{RS|Name of new CBR file:|{file$|noext}}.cbr" @{allfilepath$|filem}

... which brings me to a note on how I actually use my CBR button.

I don't tend to create CBRs from individual images within a folder (as you described doing). Rather, I group them in named folders and then RAR the folders themselves.

When I mentioned having an operation or function that would run on all selected files in sequences, the situation I was imagining would be having a folder that contained, say, four subfolders — four issues of a mini-series that I'd scanned. Ideally, I'd love to select those four folders, hit a DOpus button, and then have four .CBR files in my directory (with subfolders neatly swept into the Recycle Bin).

I'm stumped on how to accomplish this, however.

If you pass selected files to an Opus command, it executes on each selected file in succession — but if you pass selected files to an external application (like RAR), the app handles them in whatever manner it sees fit. That's why I speculated about some kind of "function" where you could define a set of Opus commands and then pass a file selection to the "function," so that Opus would execute all lines/commands in the function before moving on to the next selected file. (In that scenario, Opus might be able to RAR up a folder, rename the resulting RAR, and delete the original folder; then repeat the function on each successive selected folder, one at a time.) I don't know how possible that is, though — and I suspect that it's well outside the scope of this thread. If anyone comes along and tells me there's merit to that idea — and that there's not already a thread about it somewhere — just let me know, and I'll start a new thread. :wink:

(I'm already wary of straying too far from the original topic — though to my mind, all my "buttons to create and extract archives" are related. That may just be because I keep them in the same menu ... .)

I tend to forget about the Opus RAR plugin, since it can't (if I remember correctly) create RARs. Given the way my brain works, that might be a good thing. If I were to use Copy EXTRACT HERE on a RAR somewhere, I can almost guarantee I'd forget why that works and burn up a day trying to make RAR=single HERE work a month or two later. :unamused:

I think that's your only suggestion I chose to leave on the table. Since I understand the renaming and use that same trick in several places around Opus, I thought it might be handy to leave it in place, if only for the sake of consistency and comfort. :wink:

Once again, Steje — immense thanks for all your help! If you get a chance to chime in again, I certainly look forward to it — but, for the moment, I'm happy with all my create/extract buttons again, thanks to your and Leo's valiant efforts.

Well, O.K., there is one thing that still puzzles me. I don't understand why my newly-created .CBR files aren't selected by this code at the end of the process:

Select "{$dirname}.cbr" DESELECTNOMATCH

:question:

(The same applies to the .DIS files.)

So this is one of those situations where it's tough to code a "single" button/hotkey/context menu action that will know what you want to do for a few slightly different scenarios...

This:

@nofilenamequoting @set $dir={s|noterm} @sync "/programfiles/WinRAR/WinRAR.exe" a -r -ep1 "{s|..}{RS|Confirm new CBR filename...|{o}}.cbr" "{f}\*" Go UP Delete "{$dir}"
...should more or less do what you're describing in the multiple "folders" selected -> each to their own CBR file scenario...

Notice that you've got to get rid of the @firstfileonly argument that some of the other command variations used. In this example, you WANT Opus to process EACH selected item and use the base (in this case "folder name") name ({o}) in the @synchronously executed WinRAR commands (not sure if that's required nowadays, there've been some changes to the default behavior of Opus' handling of synchronous vs a-synchronous actions - can't hurt to explicitly instruct the command though).

Notice also, that the filespec being passed to WinRAR - as opposed to my earlier suggestions use of WinRAR's @listfiles argument - just passes the files located underneath the selected sub-folder (the {f}* argument at the end of the WinRAR command). I think this command would puke if you didn't have "folders" selected and ran it... so to my very first point in this post - you've got a few different commands for slightly different use cases. There are some additional control codes like @dirsonly and @filesonly that might let you combine different sort of actions into a single button that would behave one way or another depending on what you've got selected... but not sure if they can be used that way - and I'm coming up on my train stop again :slight_smile:...

One other note: the command above will "prompt" you for the new CBR filename for each folder you've got selected which you're running the button against. If you want to just accept a new CBR filename based on the name of the selected folder and eliminate the prompt, then just use something like "{s|..}{o}.cbr" without the middle {RS|Confirm new CBR filename...} part of the code in the example above: where again - the "{s|..}" part of the code is telling WinRAR to create the new archives in the "parent" folder of the current dir (as opposed to creating them IN the current dir, and then having to 'move' them somewhere before deleting the current dir).

Cheers...