I have a JSCRIPT function I'm trying to write and I noticed that it's running the command several times (i.e. it's running 7z.exe 5 times if I have 5 folders selected when running the function).
I would prefer to run the 7z.exe once, but pass all of the files to it in a single run command.
Can somebody help me figure out what I'm doing wrong?
Thanks for any help!
JSCRIPT
function OnClick(clickData)
{
//no = No
//ye = Echo Command (Do not Run) and leave window open
//yr = Run command and leave window open
useDebugMode = "ye"
cmd = clickData.func.command;
tab = clickData.func.sourcetab;
selFiles = new Enumerator(tab.selected);
firstSelFile = selFiles.item()
if (firstSelFile != null) {
cmd.setType("msdos")
if (useDebugMode == 'no') {
cmd.setModifier('runmode', 'min');
}
//cmd.setModifier('norunbatch');
cmd.setModifier('noprogress');
if ( useDebugMode.match(/^(ye|yr)$/) ) {
cmd.setModifier('leavedoswindowopen');
}
//Create Dialog and setup default values
Dlg = DOpus.Dlg;
Dlg.window = clickData.func.sourcetab;
Dlg.template = "Main"
Dlg.Create(); // Dialog is not visible yet.
Dlg.Control('compression-format-combobox').value = '0';
Dlg.Control('compression-level-combobox').value = '5';
Dlg.Control('compression-method-combobox').value = 'LZMA2';
Dlg.RunDlg(); // Dialog becomes visible. Won't return until dialog is closed
if (Dlg.result == 0) {
//DOpus.Output('User Cancelled');
}
else {
compressFormat = Dlg.Control('compression-format-combobox').value.name;
zipExe = '"C:\\Program Files\\7-Zip\\7z.exe"';
cmdToRun = '';
archiveType = Dlg.Control('compression-format-combobox').value.name;
delFiles = Dlg.Control('deleteinputfiles-checkbox').value;
compressLevel = Dlg.Control('compression-level-combobox').value;
cmdToRun = zipExe + ' a -t' + archiveType + (delFiles? " -sdel" : "") + ' -mx' + compressLevel + ' "{file$|noext}" "{filepath$|noterm}" ';
if ( useDebugMode == "ye" ) {
cmd.RunCommand('echo ' + cmdToRun);
}
else {
cmd.RunCommand(cmdToRun);
}
if (Dlg.Control('playfinishsound-checkbox').value == 1) {
sounder = '"X:\\Program Files\\Sounder\\sounder.exe"';
wavToPlay = '"X:\\Program Files\\Sounder\\confirm_beepy_02.wav"';
cmd.RunCommand(sounder + ' ' + wavToPlay);
}
//cmd.RunCommand('Go REFRESH');
}
}
else {
DOpus.Output('No files are selected');
}
}
Codes that insert a single filename/path like {file} will cause the command to be run once for each item.
There are other codes for inserting all names/paths at once, but since youโre using scripting you can also loop through the files and insert exactly what you need into a single line, which may be easier if you (and the program being run) need something complex.
If you checkmark "Create Multiple Archives", then the function will enumerate through the list of selected folders and run 7z.exe for each folder.
However, if you leave that unchecked, then the function will enumerate through the selected folders and create a single string containing all of the filenames.. and then it will run 7z.exe only once.
I believe this is working correctly now.
EDIT: If I recall, I think 7zip has a built in command that will let you create multiple archives. So, I should rework this so that it still only runs 7z.exe once, but with the option to create multiple archives enabled.
EDIT2: ACTUALLY, I'm not even sure about that. I think I'm completely wrong about 7z supporting that feature.