ConvertArchive copies the content of selected archives into new archive containers in a different format (7z, RAR, ZIP). The original archives are not deleted. Archives that already have a target archive will be skipped. The add-in uses the internal Copy command for all conversions.
Arguments
-
FORMATDetermines the container format. Uses the same syntax as the ARCHIVE argument. If omitted,.zipis used. -
TODetermines the target directory. If omitted, the source directory is used. -
COPYTIMESTAMPSCopies the created and modified timestamps to the new archive container. -
DRYRUNCreates and logs the internal commands without executing them. -
NOLOGDisables logging. This is overridden byDRYRUN.
Examples
ConvertArchive FORMAT=.7z // create 7z
ConvertArchive FORMAT=.zip,split:100kb // create zip, split into .z* files
ConvertArchive TO={destpath}
ConvertArchive COPYTIMESTAMPS
How to set up and use
Save CommandConvertArchive.js.txt toββββ
%appdata%\GPSoftware\Directory Opus\Script AddIns
Add the new command to a button, hotkey, context menu, etc., just like a built-in command, or run it from the FAYT Command field.
Helpful reading
How to use buttons and scripts from this forum
The script's inner workings
JScript
function OnInit(initData) {
initData.name = 'ConvertArchive';
initData.version = '2025-12-20';
initData.url = 'https://resource.dopus.com/t/convertarchive-convert-archives-to-a-different-format/58113';
initData.desc = 'Convert archives to a different format (7z, RAR, ZIP)';
initData.default_enable = true;
initData.min_version = '12.0';
}
function OnAddCommands(addCmdData) {
var cmd = addCmdData.AddCommand();
cmd.name = 'ConvertArchive';
cmd.method = 'OnConvertArchive';
cmd.desc = 'Convert archives to a different format (7z, RAR, ZIP)';
cmd.label = 'ConvertArchive';
cmd.template = '' +
'format/o[.7z,.rar,.zip],' +
'copytimestamps/s,' +
'to/o,' +
'nolog/s,' +
'dryrun/s';
cmd.hide = false;
cmd.icon = 'script';
}
function OnConvertArchive(scriptCmdData) {
var cmd = scriptCmdData.func.command;
var tab = scriptCmdData.func.sourcetab;
var args = scriptCmdData.func.args;
var fsu = DOpus.FSUtil();
var datetimePrint = 'D#yyyy-MM-dd T#MHH:mm:ss'; // milliseconds
cmd.deselect = false;
if (tab.selected_files.count == 0) {
Log('No files selected.');
return;
}
var archiveFormat = args.format || '.zip';
var targetExt = archiveFormat.split(',')[0];
cmd.ClearFiles();
Log('Enumerating...' + (args.dryrun ? ' (dry run)' : ''));
for (var e = new Enumerator(tab.selected_files); !e.atEnd(); e.moveNext()) {
Log('');
var item = e.item();
if (!item.InGroup('Archives')) {
Log('Skipped (Not an archive): ' + item);
continue;
}
var newArchive = fsu.Resolve((args.to || item.path) + '\\' + item.name_stem + targetExt);
if (fsu.Exists(newArchive)) {
Log('Skipped (Target exists): ' + item);
continue;
}
cmd.AddFile(item);
var tmpDirPath = fsu.GetTempDirPath();
var cmdLine = 'Copy' +
' FILE="' + item + '"' +
' EXTRACT=sub' +
' TO="' + tmpDirPath + '"';
Run(cmdLine);
var cmdLine = 'Copy' +
' MOVE' +
' FILE="' + tmpDirPath + '\\' + item.name_stem + '"' +
' ARCHIVE=' + archiveFormat +
' TO="' + newArchive.pathpart + '"';
Run(cmdLine);
if (args.copytimestamps) {
var cmdLine = 'SetAttr' +
' FILE="' + newArchive + '"' +
' CREATED="' + item.create.Format(datetimePrint) + '"' +
' MODIFIED="' + item.modify.Format(datetimePrint) + '"';
Run(cmdLine);
}
}
Log('');
Log('... done.');
cmd.RunCommand('Select NONE');
cmd.RunCommand('Select FROMSCRIPT SETFOCUS');
cmd.RunCommand('Select SHOWFOCUS');
// === Helper functions ===
function Log(str) {
if (args.nolog && !args.dryrun) return;
DOpus.Output(str);
}
function Run(cmdLine) {
Log(cmdLine);
if (args.dryrun) return;
cmd.RunCommand(cmdLine);
}
}