Smart archive extraction (enhanced)

Functional Overview

This Button enables the user to extract selected archives, with the option to delete the archives after extraction. Thereby it will create a target subfolder if the archive contains not only a single folder on the first level.

  • It supports all the archive types that DOPUS supports.
  • The button remains disabled unless the user select at least one archive file.
  • The button will create target subfolders for the cases where the archive contains more than one folder on the first level.
  • The user can choose in dual display mode if the archive(s) shall be extracted to the source or destination pane, with options for deleting the original archive(s) and handling the case where the target folder already exists.
  • In single display mode the Button automatically renames an existing target folder and prompts the user to keep or delete the original archive after extraction.
  • The button script checks if an archive is encrypted or the extraction failed and will not automatically delete such archives although the "delete all archives" or "Yes for all" option was chosen in the dialog boxes.
    • Limitation: The script will not recognize the failed extraction if you skip/cancel a password dialog box or enter the wrong password.
    • Accordingly the text file mentioned in the next bullet point will not list encrypted archives where the extraction failed.
  • When at least one target folder did already exist or the user selected also non-archive items or the extraction of at least one archive failed or at least one archive was encrypted, but not deleted (although "delete all archives" or "yes for all" was chosen) a text file with information about that is created in a temporary folder and opened automatically. This text file will be deleted after 10 minutes (earliest).

Explanation regarding subfolder creation

If the archive file contains only one folder on the first level

Root
└─ :file_cabinet: archive.zip
       └─ :file_folder: single folder


the button script will extract the archive directly under the root folder:

Root
├─ :file_folder: single folder
└─ :file_cabinet: archive.zip
       └─ :file_folder: single folder


But if the archive file contains several items on the first level

Root
└─ :file_cabinet: archive.zip
       ├─ :file_folder: folder 1
       ├─ :file_folder: folder 2
       └─ :spiral_notepad: readme.txt


the Button script will create a new folder named after the archive and extract the archive into this new folder:

Root
├─ :file_folder: archive
 |     ├─ :file_folder: folder 1
 |     ├─ :file_folder: folder 2
 |     └─ :spiral_notepad: readme.txt
└─ :file_cabinet: archive.zip
       ├─ :file_folder: folder 1
       ├─ :file_folder: folder 2
       └─ :spiral_notepad: readme.txt

Included language overlays

  • English
  • German
  • French

How to Install

  1. Simply drag and drop the dcf file onto an appropriate toolbar. See also How to use buttons and scripts from this forum

  2. If your display language is not set to English: Open the customize mode and edit the button. Change in the scriptcode tab in the first line the file type name “Archives” to the display name of this file type group of your display language. Additionally, you can rename the Button like you want.

How to change the default behavior
  • If you want to change the default setting (pre-selection) for dual display mode and the case, that a target folder already exist you have to change the numerical value in the script line Dlg.Control("combo1").SelectItem(0); (currently row 57) to one of the values mentioned above this line.

  • If you want to change the default setting (pre-selection) of the archive-deletion for dual display mode you must change this via the dialog editor for the dialog “destination” (or directly in the code).

  • The default setting regarding handling of existing target folders for single display mode can only be changed directly in the code via rewriting/copy the wanted behavior from the dual display section.


How to Use


Available options for the case that a target folder already exists (only dual display mode)
  • Rename the old folder (default / pre-selected)
    The existing folder will be renamed and afterwards the archive will be extracted into a new created folder

  • Replace the old folder
    The existing folder will be deleted to the recycle bin (at least if you did not change the global setting that the recycle bin will not be used) and afterwards the archive will be extracted into a new created folder

  • Skip the archive
    The archive that has the same name as an already existing folder will be skipped. This archive will not be deleted no matter which delete-option was chosen in any dialog.

  • Skip same-named files
    The archive will be extracted into the already existing folder and when there is a conflict due to same-named files the old file will be kept.

  • Replace same-named files
    The archive will be extracted into the already existing folder and when there is a conflict due to same-named files the old file will be overwritten.


  1. Choose the archives you want to have extracted

  2. Dual display mode:

  • Choose an option for the case where a target folder already exists
  • Choose a delete option (the default selection is “delete all archives”)
  • Choose to extract the archives to the source or destination pane.

    Destination

    Single display mode:
    The script directly extracts the archives to the source pane. If a target folder already exists it will rename the existing folder before extraction.
  1. When you have chosen in dual display mode “Delete-prompt for each archive” or you are using the single display mode a dialog box will be displayed which offers the option to delete the currently processed archive:

    delete

  2. If you have selected not only archives, but also non-archive items, a target folder did already exist, the extraction of at least one archive failed or/and at least one archive was encrypted, but not deleted (although "delete all archives" or "yes for all" was chosen) a text file with information about that is created and opened. (This text file will be deleted after 10 minutes (earliest).)

Credits

I adapted this Button from freds “Smart Archive Extraction”. See Smart archive extraction
A big thank you to @fred. :blush:

Based on a user request for a function that the archive are deleted after extraction I started to change the script and then developed it further. So I created a new topic after alignment with fred.

Thanks to @onedot3 for testing the button script a lot.
Thanks to @khalidhosain for the hint regarding the deletion of archives although the extraction failed or the archives are encrypted (but not successfully extracted).

Further Development

Please share any problems or ideas that could improve this Button.

Button Download

Warning : Only for DOpus v12.22 and higher.

V1.0.223
Extract.dcf (37.4 KB)

V1.0.224
Extract.dcf (37.2 KB)

  • Corrections for the French localisation

V1.0.525b (not fully tested, but should work correctly)
Extract.dcf (39.8 KB)

  • Encrypted archives and archives were the extraction fails will never be deleted

V1.1.531
Extract.dcf (44.5 KB)

  • The script checks if the archive is encrypted
  • The script checks if the encryption was successfull (but will not recognize the failed extraction if a password dialog box is skipped/canceled.)
  • Archives which are encrypted or where the extraction failed will not be deleted if "delete all archives" or "yes for all" in the dialog boxes were chosen.
  • The last dialog box, which informed about changed folders or skipped items is replaced by a txt file, which is created in a temporary folder and automatically deleted after 10 minutes (earliest).
  • This text file is only created when an item was not an archive, existing target folders were changed, an extraction failed or an archive was encrypted, but not deleted (and "delete all" was chosen).
9 Likes

Here is the xml dialog corrected for french.

<resources>
	<resource name="delete" type="dialog">
		<dialog fontsize="12" height="80" lang="english" resize="yes" title="Delete archive?" width="168">
			<languages>
				<language height="80" lang="deutsch" title="Archiv löschen?" width="168" />
				<language height="80" lang="francais" title="Supprimer l&apos;archive?" width="168" />
			</languages>
			<control close="4" default="yes" height="14" name="button4" resize="xy" title="N&amp;o for all" type="button" width="50" x="100" y="59">
				<languages>
					<language height="14" lang="deutsch" title="N&amp;ein fĂĽr alle" width="50" x="100" y="59" />
					<language height="14" lang="francais" title="Non &amp;pour tous" width="50" x="100" y="59" />
				</languages>
			</control>
			<control close="3" height="14" name="button3" resize="y" title="Y&amp;es for all" type="button" width="50" x="18" y="59">
				<languages>
					<language height="14" lang="deutsch" title="J&amp;a fĂĽr alle" width="50" x="18" y="59" />
					<language height="14" lang="francais" title="O&amp;ui pour tous" width="50" x="18" y="59" />
				</languages>
			</control>
			<control close="2" height="14" name="button2" resize="xy" title="&amp;No" type="button" width="50" x="100" y="39">
				<languages>
					<language height="14" lang="deutsch" title="&amp;Nein" width="50" x="100" y="39" />
					<language height="14" lang="francais" title="&amp;Non" width="50" x="100" y="39" />
				</languages>
			</control>
			<control close="1" height="14" name="button1" resize="y" title="&amp;Yes" type="button" width="50" x="18" y="39">
				<languages>
					<language height="14" lang="deutsch" title="&amp;Ja" width="50" x="18" y="39" />
					<language height="14" lang="francais" title="&amp;Oui" width="50" x="18" y="39" />
				</languages>
			</control>
			<control halign="center" height="9" name="text" resize="w" title="Should this archive be deleted?" type="static" valign="top" width="118" x="25" y="4">
				<languages>
					<language height="9" lang="deutsch" title="Soll dieses Archiv gelöscht werden?" width="118" x="24" y="4" />
					<language height="9" lang="francais" title="Faut-il supprimer cette archive?" width="118" x="25" y="4" />
				</languages>
			</control>
			<control halign="center" height="17" name="archname" resize="wh" title="Archivename" type="static" valign="top" width="154" x="7" y="16">
				<languages>
					<language height="17" lang="francais" title="nom de l&apos;archive" width="154" x="7" y="16" />
				</languages>
			</control>
		</dialog>
	</resource>
	<resource name="destination" type="dialog">
		<dialog fontsize="12" height="128" lang="english" standard_buttons="cancel" title="Set extraction settings" width="147">
			<languages>
				<language height="128" lang="deutsch" title="Einstellungen fĂĽr die Extraktion festlegen" width="147" />
				<language height="128" lang="francais" title="Définir les paramètres de l&apos;extraction" width="155" />
			</languages>
			<control close="1" default="yes" height="14" name="source" title="&amp;Source" type="button" width="50" x="12" y="88">
				<languages>
					<language height="14" lang="deutsch" title="Quelle" width="50" x="12" y="88" />
				</languages>
			</control>
			<control close="2" height="14" name="destination" title="&amp;Destination" type="button" width="50" x="83" y="88">
				<languages>
					<language height="14" lang="deutsch" title="Ziel" width="50" x="83" y="88" />
					<language height="14" lang="francais" title="&amp;Destination" width="50" x="93" y="88" />
				</languages>
			</control>
			<control height="30" name="group1" title="Extract in:" type="group" width="132" x="7" y="76">
				<languages>
					<language height="30" lang="deutsch" title="Entpacke nach:" width="132" x="7" y="76" />
					<language height="30" lang="francais" title="Extraire dans :" width="142" x="6" y="76" />
				</languages>
			</control>
			<control height="39" name="group2" title="After the extraction:" type="group" width="132" x="7" y="32">
				<languages>
					<language height="39" lang="deutsch" title="Nach der Extraktion:" width="132" x="7" y="32" />
					<language height="39" lang="francais" title="Après extraction:" width="142" x="6" y="32" />
				</languages>
			</control>
			<control checked="yes" group="yes" height="10" name="radio1" title="Delete all archives" type="radio" width="108" x="10" y="41">
				<languages>
					<language height="10" lang="deutsch" title="Alle Archive löschen" width="108" x="10" y="41" />
					<language height="10" lang="francais" title="Supprimer toutes les archives" width="108" x="10" y="41" />
				</languages>
			</control>
			<control height="10" name="radio2" title="Delete-query for each archive" type="radio" width="108" x="10" y="50">
				<languages>
					<language height="10" lang="deutsch" title="Löschabfrage für jedes Archiv" width="108" x="10" y="50" />
					<language height="10" lang="francais" title="Demander pour chaque archive" width="136" x="10" y="50" />
				</languages>
			</control>
			<control height="10" name="radio3" title="Delete no archive" type="radio" width="108" x="10" y="59">
				<languages>
					<language height="10" lang="deutsch" title="Kein Archiv löschen" width="108" x="10" y="59" />
					<language height="10" lang="francais" title="Ne rien supprimer" width="108" x="10" y="59" />
				</languages>
			</control>
			<control height="25" name="group3" title="When the target folder already exists:" type="group" width="132" x="7" y="2">
				<languages>
					<language height="25" lang="deutsch" title="Wenn der Zielordner bereits existiert:" width="132" x="7" y="2" />
					<language height="25" lang="francais" title="Lorsque le dossier cible existe déjà :" width="142" x="7" y="2" />
				</languages>
			</control>
			<control height="40" name="combo1" type="combo" width="125" x="10" y="11" />
		</dialog>
	</resource>
	<resource name="information" type="dialog">
		<dialog fontsize="12" height="125" lang="english" resize="yes" standard_buttons="ok" title="Information" width="156">
			<languages>
				<language height="125" lang="deutsch" title="Information" width="156" />
				<language height="125" lang="francais" title="Information" width="156" />
			</languages>
			<control halign="left" height="8" name="static1" title="static1" type="static" valign="top" width="140" x="8" y="5" />
			<control height="40" name="listbox1" nosel="yes" resize="wh" type="listbox" width="140" x="8" y="16" />
			<control halign="left" height="16" name="static2" resize="y" title="The following items are not archives and have been skipped:" type="static" valign="top" width="139" x="8" y="63">
				<languages>
					<language height="16" lang="deutsch" title="Folgende Elemente sind keine Archive und wurden ĂĽbersprungen:" width="140" x="8" y="63" />
					<language height="16" lang="francais" title="Les éléments suivants ne sont pas des archives et ont été ignorés:" width="140" x="8" y="63" />
				</languages>
			</control>
			<control height="20" name="listbox2" nosel="yes" resize="yw" type="listbox" width="140" x="8" y="82" />
		</dialog>
	</resource>
	<resource type="strings">
		<strings lang="deutsch">
			<string id="merged">Ordner mit ZusammenfĂĽhrungen:</string>
			<string id="mergeReplace">Gleichnamige Dateien ersetzen</string>
			<string id="mergeSkip">Gleichnamige Dateien ĂĽberspringen</string>
			<string id="rename">Bestehenden Ordner umbenennen</string>
			<string id="renameOld">Folgende Ordner wurden umbenannt:</string>
			<string id="replace">Bestehenden Ordner ersetzen</string>
			<string id="replaceOld">Folgende Ordner wurden ersetzt:</string>
			<string id="skip">Archiv ĂĽberspringen</string>
			<string id="skipA">Folgende Archive wurden ĂĽbersprungen:</string>
		</strings>
		<strings lang="english">
			<string id="merged">Folders with merges:</string>
			<string id="mergeReplace">Replace same-named files</string>
			<string id="mergeSkip">Skip same-named files</string>
			<string id="rename">Rename existing folder</string>
			<string id="renameOld">The following folders have been renamed:</string>
			<string id="replace">Replace existing folder</string>
			<string id="replaceOld">The following folders have been replaced:</string>
			<string id="skip">Skip the archive</string>
			<string id="skipA">The following archives were skipped:</string>
		</strings>
		<strings lang="francais">
			<string id="merged">Dossiers avec fusions:</string>
			<string id="mergeReplace">Remplacez les fichiers du mĂŞme nom</string>
			<string id="mergeSkip">Ignorer les fichiers du mĂŞme nom</string>
			<string id="rename">Renommer le dossier existant</string>
			<string id="renameOld">Les dossiers suivants ont été renommés:</string>
			<string id="replace">Remplacer le dossier existant</string>
			<string id="replaceOld">Les dossiers suivants ont été remplacés:</string>
			<string id="skip">Ignorer l&apos;archivage</string>
			<string id="skipA">Les archives suivantes ont été ignorées:</string>
		</strings>
	</resource>
</resources>
1 Like

@fred Thank you. So for Frensh there must be always a space before "?" and ":", right? I corrected that also for the rest of the script. :slight_smile:

Actually it is a non-breakable half-space but a space is ok. And it is French with C. Not FrenSh.

1 Like

Oh, Sorry! :slight_smile: French.

Please find my suggestion for the English text:

Smart Archive Extraction (enhanced)

Functional Overview

This Button enables the user to extract selected archives, with the option to delete the archives after extraction.

  • It supports all the archive types that DOPUS supports.
  • The programmed Button will create target subfolders for the cases where the archive contains more than one folder on the first level.
  • The Button remains disabled until the user selects at least one archive file.
  • The Button will work in the DOPUS Dual Display mode. The user can extract the archive to the source or destination pane, with options for deleting the original archive(s) and handling the case where the target folder already exists.
  • The Button automatically renames an existing target folder in Single Display mode and prompts the user to keep or delete the archive after extraction.
  • An information dialogue box describing changes will display:
    • After the extraction completes and
    • When at least one target folder already exists or,
    • When the user selected non-archive files.

Subfolder creation

If the archive file contains only one folder on the first level,

Root
└─ archive.zip
└─ single folder

the Button script will extract the folder directly under the root folder:

Root
├─ single folder
└─ archive.zip
└─ single folder

If the archive file contains several items on the first level,

Root
└─ archive.zip
├─ folder 1
├─ folder 2
└─ readme.txt

the Button script will create a new folder, name it with the archive file name, and extract the archived folders to this folder:

Root
├─ archive
| ├─ folder 1
| ├─ folder 2
| └─ readme.txt
└─ archive.zip
├─ folder 1
├─ folder 2
└─ readme.txt

Included language overlays

English

German

French

How to Install

  • Drag and drop the dcf file onto an appropriate toolbar. For further information review: How to use buttons and scripts from this forum
  • To change the display language from the default English:
    • Open the customize mode and edit the Button.
    • In the Scriptcode Tab, change the first line of the file type name “Archives” to your preferred display language.
    • Additionally, you can rename the Button.

How to Use

Here are the options for the case when a target folder already exists (only in DOPUS Dual Display mode)

  • Choose the archives you want to extract.

  • Dual Display mode:

    • Choose an option for the case where a target folder already exists
    • Choose a delete option (the default selection is “delete all archives”)
    • Choose to extract the archives to the source or destination pane.
  • Single Display mode:
    The script extracts the archives to the source folder, but it will rename the existing folder before extraction if a target folder exists.

  • In dual display mode, when you have selected “Delete-prompt for each archive” or using the single display mode, the script will open a dialogue box and offer the user the option to delete the current processed archive:

  • Suppose the user has selected both archived and non-archivde files, or a target folder that already exists. In that case, the script will open a dialogue box with information about changed folders or skipped non-archive files:

Credits

I adapted this Button from fred’s “Smart Archive Extraction”. See Smart archive extraction 2.

I send a huge thank you to @fred.

Based on a user request to delete an archive after extraction, I changed the script and then developed it further. So after consulting with fred, I created a new button topic.

Further Development

Please share any problems or ideas that could improve this Button. I would welcome support regarding the English and French translations. Since I have not programmed in years, I would also welcome suggestions concerning the script code.

My testing of the Button indicates that it is working correctly.

1 Like

@Mosed Thank you for this button
After doing my own testing think I have tried every combination and every thing worked as expected.

1 Like

Thank you so much for this enhanced button.

This works beautifully, thanks!

image
I face a problem with the Enhanced button. when I have Select 100+ RAR file for extract, but some of the file has displayed this kind of error....... the archive appears to be invalid or damaged; Then I Click on Skip. So the file does not be extracted (because it has some problem) and the file also deleted. Because before from here I have selected Delete All Archives.
Destination
So I want If some file have problem for proper extract then Those file should not be Deleted even I select Delete All Archives. Because this delete; I don't get a 2nd chance to repair those problematic archive file

1 Like

Thank you for this hint. I did not consider a failing extractation.

Does someone has a hint how I can include a check regarding this "skip"?
I think I have to add something in the IF clause and a specific variable must have a specific value.

Also the abort should I consider to abort the whole extractation.

But how do I get the return value from this dialog?

Items in the Command's file list should have their failed properties set if they failed.

The script uses Copy FILE=... EXTRACT, so cmd.files will remain empty, I am afraid.

cmd.results.result will only be zero, if the extraction gets aborted, not if the file gets skipped.

Tricky!

Well, if I remember correctly, a warning and good advice were given... :slight_smile:

1 Like

Ok. Is it not possible to check if this error message is shown?
The dialog will also return return values, right?

If you replace this style

cmd.RunCommand('Copy EXTRACT=sub FILE="D:\\error2.rar"');

with this

cmd.ClearFiles();
cmd.AddFile('D:\\error2.rar');
cmd.RunCommand('Copy EXTRACT=sub');

cmd.files(0).failed will be false, if the extraction was ok, and true in all other cases.

At least so it seems :wink:

If you want to test more:

function OnClick(clickData) {
    var cmd = clickData.func.command;
    cmd.deselect = false;

    DOpus.ClearOutput();
    cmd.RunCommand('Set UTILITY=otherlog');

    // cmd.RunCommand('Copy EXTRACT=sub FILE="D:\\error2.rar"');

    cmd.ClearFiles();
    cmd.AddFile('D:\\error2.rar');
    cmd.RunCommand('Copy EXTRACT=sub');

    DOpus.Output('cmd.files.count =     ' + cmd.files.count);
    DOpus.Output('cmd.files(0).failed = ' + cmd.files(0).failed);
    DOpus.Output('cmd.results.result =  ' + cmd.results.result);
}
2 Likes

@lxp: thank you

@khalidhosain Please try this one in a test environment (perhaps you can send me a damaged archive, because I do not have one):
Extract.dcf (38.6 KB)

1 Like

Thanks Mosed I had tested the updated button. now damaged file doesn't delete

Here a damaged file link: Download Here

Here another issue; some files have password. when I select 100+ files for extract that time I want to skip or abort the password protected files. maybe I can't remember the password, or don't know the password or some other reason I have to skip or abort. The updated Extract button have delete the original rar files in skip or abort both case. Here is a Password Protected files

Thank you for the files. Quite big... :smiley:

Edit: for me both files are damaged. No password dialog visible.
But I created an own password protected zip and it gets deleted even when it is skiped. But cmd.files(0).failed is "false".

So the extract is successul, but then canceled. The subdirectory is also created, but empty.

Is it possible to check if an archive is password protected? I guess the easiest solution is to not delete such archives in any case.

Edit 2: If you use the extract all command in the contect menu for a password protected archive the whole process simply fails. Is that a bug?
If you use the submenu regarding extraction Dopus tries to extract and if you skip the newly created subfolder is deleted.

1 Like