JScript: Command to select a file by path?

Hi. I have developed the script below. It was based on this one by lxp: https://resource.dopus.com/t/duplicate-and-rename/39142. When it's complete, I'll share it in the working scripts section. The language is JScript.

Desired Functionality

  1. User selects a file.
  2. User clicks a toolbar button.
  3. Script checks: just 1 file is selected.
  4. Script checks: selected file's filename contains a version number that matches 1of 3 possible regex patterns.
  5. If those conditions are met, then...
  6. Script creates a new file which is exact copy of source file.
  7. New file's filename is same as source file, except that rightmost section of its file version is incremented by 1.
  8. Source file is deselected in the lister.
  9. Newly created file is selected in the lister.
  10. User can open / execute new file by pressing "enter".


All steps above are working, except for step 9.
How do I achieve step 9?
That is, what is the JScript command to select (or ?set focus to) the newly created file in the lister?

In the script, the variable that holds the filename is "newName".

This doesn't work:

select newName;

Do I need to specify the full path, or indicate that the file is in the active lister, or something?


Can I change function name and parameter?
Or is one or both of those a dopus or jscript command or keyword?
I copied them both from the script by lxp (above).


function OnClick(clickData)


function CopyFileIncrementVersionNumber(sourceFile)

From experimentation, it seems that it's OK to change the parameter name "clickData", but not the function name "OnClick".

Full script below. Probably more whitespace and longer variable names than some of you would like!

function OnClick(clickData)

    var cmd;
    var tab;
    var item;
    var stem;
    var ext;
    var textPart01;
    var textPart02;
    var versionPart01;
    var versionPart02;
    var versionPart03;
    var versionPart01Pad;
    var versionPart02Pad;
    var versionPart03Pad;
    var regEx1;
    var regEx2;
    var regEx3;
    var matched1;
    var matched2;
    var matched3;
	var createfile;
    var newName;
    var cmdLine;
    cmd = clickData.func.command;
    tab = clickData.func.sourcetab;
    cmd.deselect = false;
    if (tab.selected_files.count != 1)
    item = tab.selected_files(0);
    stem = item.name_stem;
    ext = item.ext;
	createfile = false;

	// Version Number Format: "(v01)"
    regEx1 = /^(.*)\(v(\d+)\)(.*)$/;
    matched1 = stem.match(regEx1);

    if (matched1)

		createfile = true;
	    textPart01 = matched1[1];
	    textPart02 = matched1[3];
	    versionPart01 = matched1[2];
	    versionPart01Pad = versionPart01.length;
	    // next line: may get data type error if was string now integer
	    versionPart01 = parseInt(versionPart01,10) + 1;
	    versionPart01 = ZeroPad(versionPart01,versionPart01Pad);
	    newName = textPart01 + '(v' + versionPart01 + ')' + textPart02 + ext;
	// Version Number Format: "(v01.01)"
	regEx2 = /^(.*)\(v(\d+).(\d+)\)(.*)$/;
    matched2 = stem.match(regEx2);
    if (matched2)

		createfile = true;
		textPart01 = matched2[1];
	    textPart02 = matched2[4];
	    versionPart01 = matched2[2];
	    versionPart02 = matched2[3];
	    versionPart02Pad = versionPart02.length
	    // next line: may get data type error if was string now integer
		versionPart02 = parseInt(versionPart02,10) + 1;
	    versionPart02 = ZeroPad(versionPart02,versionPart02Pad);
	    newName = textPart01 + '(v' + versionPart01 + '.' + versionPart02 + ')' + textPart02 + ext;
	// Version Number Format: "(v01.01.01)"
	regEx3 = /^(.*)\(v(\d+).(\d+).(\d+)\)(.*)$/;
    matched3 = stem.match(regEx3);
    if (matched3)

		createfile = true;
	    textPart01 = matched3[1];
	    textPart02 = matched3[5];
	    versionPart01 = matched3[2];
	    versionPart02 = matched3[3];
	    versionPart03 = matched3[4];
	    versionPart03Pad = versionPart03.length
	    // next line: may get data type error if was string, but now integer
	    versionPart03 = parseInt(versionPart03,10) + 1;
	    versionPart03 = ZeroPad(versionPart03,versionPart03Pad);
	    newName = textPart01 + '(v' + versionPart01 + '.' + versionPart02 + '.' + versionPart03 + ')' + textPart02 + ext;
    if (!createfile)
    cmdLine = 'Copy DUPLICATE FILE="' + item + '" AS="' + newName + '"';

function ZeroPad(numberString, digitCount)

    numberString = numberString + "";
    while(numberString.length < digitCount)
        numberString = "0" + numberString;
    return numberString;

Select PATTERN="File Name.ext" EXACT (run via Command.RunCommand) will select a file from a script.

Hi Leo.

OK. I've got it working. Thanks for the pointer.

I had a bit of difficulty deselecting the source file. I read this page, but wasn't sure how to combine arguments. Seems like they just line up, separated by a space. Right?


Anyway, it works if I add the new code (in lines 3 and 4 below) straight after existing code (in lines 1 and 2).

    cmdLine = 'Copy DUPLICATE FILE="' + item + '" AS="' + newName + '"';
    cmdLine = 'Select PATTERN="' + newName + '" EXACT DESELECTNOMATCH';

If anyone reads this post later, and wonders what the answer to Question 2 above was, these pages may help. They refer to Directory Opus v12.




As always, Leo et al, thanks for your continued development of the product and for your technical support!