Automatically rename new files added to a specific folder

I don't know your specific use case. May be running a rename script on demand is almost as good?

Here's a script that sets up the Advanced Renamer for the files in the source.

// https://resource.dopus.com/t/automatically-rename-new-files-added-to-a-specific-folder/49835

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

    if (tab.all.count == 0) return;

    var re = /^(\d+)$/;
    var maxNum = 0;

    cmd.ClearFiles();

    for (var e = new Enumerator(tab.all); !e.atEnd(); e.moveNext()) {
        var item = e.item();
        var tmp = item.name_stem.match(re);
        if (tmp) {
            var num = Number(tmp[1]);
            if (num > maxNum) maxNum = num;
        } else {
            cmd.AddFile(item);
        }
    }

    ++maxNum;

    var cmdLine = 'Rename' +
        ' ADVANCED' +
        ' PATTERN=*' +
        ' TO=[#]' +
        ' NUMBER=' + maxNum +
        ' IGNOREEXT';

    // DOpus.Output(cmdLine);
    cmd.RunCommand(cmdLine);
}
XML
<?xml version="1.0"?>
<button backcol="none" display="both" label_pos="right" textcol="none">
	<label>49835</label>
	<icon1>#newcommand</icon1>
	<function type="script">
		<instruction>@script JScript</instruction>
		<instruction>// https://resource.dopus.com/t/automatically-rename-new-files-added-to-a-specific-folder/49835</instruction>
		<instruction />
		<instruction>function OnClick(clickData) {</instruction>
		<instruction>    var cmd = clickData.func.command;</instruction>
		<instruction>    var tab = clickData.func.sourcetab;</instruction>
		<instruction>    cmd.deselect = false;</instruction>
		<instruction />
		<instruction>    if (tab.all.count == 0) return;</instruction>
		<instruction />
		<instruction>    var re = /^(\d+)$/;</instruction>
		<instruction>    var maxNum = 0;</instruction>
		<instruction />
		<instruction>    cmd.ClearFiles();</instruction>
		<instruction />
		<instruction>    for (var e = new Enumerator(tab.all); !e.atEnd(); e.moveNext()) {</instruction>
		<instruction>        var item = e.item();</instruction>
		<instruction>        var tmp = item.name_stem.match(re);</instruction>
		<instruction>        if (tmp) {</instruction>
		<instruction>            var num = Number(tmp[1]);</instruction>
		<instruction>            if (num &gt; maxNum) maxNum = num;</instruction>
		<instruction>        } else {</instruction>
		<instruction>            cmd.AddFile(item);</instruction>
		<instruction>        }</instruction>
		<instruction>    }</instruction>
		<instruction />
		<instruction>    ++maxNum;</instruction>
		<instruction />
		<instruction>    var cmdLine = &apos;Rename&apos; +</instruction>
		<instruction>        &apos; ADVANCED&apos; +</instruction>
		<instruction>        &apos; PATTERN=*&apos; +</instruction>
		<instruction>        &apos; TO=[#]&apos; +</instruction>
		<instruction>        &apos; NUMBER=&apos; + maxNum +</instruction>
		<instruction>        &apos; IGNOREEXT&apos;;</instruction>
		<instruction />
		<instruction>    // DOpus.Output(cmdLine);</instruction>
		<instruction>    cmd.RunCommand(cmdLine);</instruction>
		<instruction>}</instruction>
	</function>
</button>

How to use buttons and scripts from this forum