There is a new and enhanced version here. It is not maintained by me. I don’t have time.
Purpose
Extract selected archives and create a target subfolder only when needed. All archives type supported by DOpus are processed. See group archives in file types.
Let’s say you have one archive in your D: drive.
If the archive is for instance structured as
(D:)
└──🤐archive.zip
└── 📁only one directory
then extract its content such as you get
(D:)
├──📁only one directory
└──🤐archive.zip
└── 📁only one directory
Wow. Very great. Until know I checked every zip if I have to extract to "root" or new folder...
Automatically deletion would be nice sometimes, but not everytime I think. But perhaps the target folder dialog could be used for that with four buttons, e.g.:
Source
Source with archive deletion
Destination
Destination with archive deletion
Or a prompt after extraction if the archive shall be deleted. But four buttons would be less Inputs.
A prompt afterwards would be better. But I don’t have time for now take care of it. If someone else want to add this feature and share, I will update my first post including it. Just be sure that if multiple archives are extracted, only one final prompt pops up to send all of them to the bin.
The function "Skips selected item if it’s not an archive and warns user later" does only work partially. The item is skipped, but there is no warning.
I tried another improvement and it seems to work: If nothing is selected I do not want to get a warning, I want that the button is disabled.
Therefore I added this command in first line:
@disablenosel:files
Better would be something related to archives, but until now I did not find a solution therefore beside adding every possible archive file ending to the command @disablenosel:type=*.zip
Has someone an idea?
And I removed the If / else loop for the warning if no file is selected or process the data. So, I deleted the if loop and removed the else {}. The content of the else-loop is still there.
@disablenosel:files
function OnClick(clickData) {
var cmd = clickData.func.command;
var tab = clickData.func.sourcetab;
var isDual = clickData.func.command.IsSet("DUAL=on");
var fsu = DOpus.FSUtil();
var Dlg = DOpus.Dlg;
var selWarning = false;
var isTargetSet = false;
var canceled = false;
cmd.deselect = false;
cmd.SetDestTab(tab);
// cmd.RunCommand('Set UTILITY=otherlog');
DOpus.ClearOutput();
DOpus.Output("SMART EXTRACT STARTS\n");
DOpus.Output("is dual : " + isDual);
DOpus.Output("Enumerating...\n");
for (var e = new Enumerator(tab.selected_files); !e.atEnd(); e.moveNext()) {
var item = e.item();
if (!canceled) {
// Skips selected item if it’s not an archive and warns user later.
if (!item.InGroup("Archives")) {
DOpus.Output("Error (not an archive file) : '" + item.name + "'");
selWarning = true;
continue;
}
// If it’s dual display, ask user where to extract
if (isDual && !isTargetSet) {
isTargetSet = true;
Dlg.window = tab;
Dlg.icon = "question";
Dlg.top = true;
Dlg.template = "destination";
var retVal = Dlg.Show();
// DOpus.Output("pressed button : "+retVal);
switch (retVal) {
case 1: // source
// instruction
DOpus.Output("pressed button : source");
break;
case 2: // destination
DOpus.Output("pressed button : destination");
cmd.SetDestTab(clickData.func.desttab);
break;
default:
// cancel
DOpus.Output("pressed button : cancel");
canceled = true;
DOpus.Output("\nSMART EXTRACT END\n");
continue;
break;
}
}
var folderEnum = fsu.ReadDir(item);
var folderItem = folderEnum.Next();
if (folderItem.is_dir && folderEnum.complete) {
var cmdLine = 'Copy FILE="' + item + '" WHENEXISTS=rename EXTRACT';
} else {
var cmdLine = 'Copy FILE="' + item + '" WHENEXISTS=rename EXTRACT=sub';
}
DOpus.Output(cmdLine);
cmd.RunCommand(cmdLine);
}
if (selWarning) {
Dlg.window = tab;
Dlg.icon = "warning";
Dlg.top = true;
Dlg.template = "warning";
Dlg.Show;
}
DOpus.Output("\nSMART EXTRACT END\n");
}
}
Regarding deleting lxp wrote something in the original topic:
I want to make some more improvements. Then I can share the changed button.
EDIT: Another option is to use simply cmd.RunCommand('Delete FILE="' + item + '"'); Then Opus asks if the file shall be deleted.
But I have to check more in details the options...
Now the script does not terminate after the "Skips selected item if it’s not an archive and warns user later" area when only e.g. a txt file is selected and you get the warning message.
Now I can work on the delete-function. I'm thinking about radio buttons in the source/destination dialog with a standard setting for delete or no delete.
And do I see it right that the break; in row 60 (switch --> default) is not necessary, because the last option in a switch does this automatically.
The correct button disable-command for archive-files is @disablenosel:type=grp:Archives for English language. For some reason it is language-sensitive. in German it is @disablenosel:type=grp:Archive.
The first version is available for testing. It seems to work fine, but I tried only dual-lister right now.
But this is the simple one which ask for each archive if it should be deleted.
I want to improve this further.
Changes compared to original script:
Removed check and message for the case, that nothing is selected at all
Added the function that the button is disabled as long as no archive file is selected
Fixed the issue that the warning "Some selected files were not archives." did not appear (relevant if you select more then one file)
Added a dialog which asks for each archive if it should be deleted. The dialog shows the archive name
Added German translation (the new delete-dialog does not have Frensh translation until version v2022.02.12b)
Added possibility to choose "yes for all" and "no for all" in the delete-dialog (so the delete-dialog will only show up once when multiple files are selected for extracting)
Added Frensh translation for the delete-dialog (via google translate )
added in the target lister dialog (only for dual display mode) radio buttons to choose between "delete all archives"; " delete-query for each Archive" and "delete no archive". Standard setting is "delete all archives" - can be changed via dialog editor.
separate delete dialog is only displayed now in single display mode or when you chose "delete-query for each archive" in the target lister dialog.
.
.
Important: The @disablenosel command is language sensitive. (Would be nice if this will be fixed). So the user has to adapt the first line of the script to the display language for the Archives file group.
e.g.:
English: @disablenosel:type=grp:Archives
German: @disablenosel:type=grp:Archive
@Mosed
Have just tried out V2 tried dual and single lister both work OK for everything
Except
Fixed the issue that the warning "Some selected files were not archives." did not appear (relevant if you select more then one file)
Which only displays the Some selected files were not archives when the Cancel button is pressed
@onedot3: You are right. Thank you. The warning does not appear at all according my testing now.
But I do not know why. I have a similar variant with the primary difference, that I use "Dlg.show" instead of "Dlg.RunDlg.
Do I have to add something due to Dlg.RunDlg?
The relevant variable has the value "true" directly before the dialog code, so the dialog should appear.
This button works as written regarding the warning, but does not display the item name in the delete dialog: Extract V2a.dcf (12.9 KB)
Left the V2a, right the V2. That is the only difference in the code.
if (selWarning) {
Dlg.window = tab;
Dlg.icon = "warning";
Dlg.top = true;
Dlg.template = "warning";
Dlg.Create();
var x = Dlg.RunDlg;
}
But why? The Dlg.Create(); from the delete dialog seems to "break" Dlg.Show for the subsequent script.
EDIT: ok, the "var x =" is not necessary before the "Dlg.RunDlg".
@Mosed That was quick
Tried V2a Just seen your edit
New V2 better
Noticed
If extracting Dual Lister to Destination and I delete then the only files left selected are the non archive so do not really need the "Some selected files were not archives". Without delete all files are left Selected
If extracting Dual Lister to Source with or without delete then all files a deselected straight away, also Single Lister they are all deselected, if only it worked the same as Dual Lister to Destination.
This is the same as V2
As I always work from Right Source to Left Destination
Having the Source button on the left and the Destination button on the right feels all wrong to me.
Just before you posted V2 was trying to work out how to swap them but could not get it to work.
Would it be easy to show me what to change
I think the warning is more an information that a non-archive file was selected, but it was ignored.
You can easily change it. Choose customize for the button. Choose the ressource-tab. Choose from the menu the dialog "destination" and change the button position.
@Mosed I'd been trying to change button position by opening Extract V2.dcf in note pad. As others have said you learn something new everyday, that was a lot easier.
Thanks
Edit: And I also added my target solution. If you use dual display you can choose in the target lister dialog if the Archives shall be deleted via radio buttons with a standard setting. So in general you only have to choose the target lister and only if necessary you have to choose another delete-setting.
But would be nice if someone would look over the code and says if improvements are necessary.
@Mosed Have downloaded V2022.02.14b have tested every combination I think as there are a lot.
The only thing is if you don't delete the archive and then extract the same archive and if just files in the archive, there is no warning and the files are extracted into the folder and (2) added at end, if there is a folder it brings up the Confirrn Folder Merge
But this behavior is identical to the original button I think. But I can check if this can be improved. (Its my first button / script change I do, so also for me it is learning by doing).
@Mosed Have been testing with changing whenexists to ask , skip etc which do work.
But would it be better if when creating the folder it checked if there was already a folder maybe easier to say than do.