Rename files with number sequentially

I have a file named: screenshot_20211226_204621 and I want to rename other files by changing only the last file numbers sequentially, for example 204622, 204623 and so on, keeping the name and the date.
How can I do it?

This script grabs the data from the first selected file and populates the Advanced Renamer with it.

//  https://resource.dopus.com/t/rename-files-with-number-sequentially/40178

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

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

    var item = tab.selected(0);

    var part1 = item.name_stem.replace(/(.*_)(\d+)/, '$1');
    var part2 = item.name_stem.replace(/(.*_)(\d+)/, '$2');

    var cmdLine = ('Rename ADVANCED PATTERN="' + part1 + '*" TO="' + part1 + '[#]" NUMBER=' + part2);
    // DOpus.Output(cmdLine);
    cmd.RunCommand(cmdLine);
}
Button as XML
<?xml version="1.0"?>
<button backcol="none" display="both" textcol="none">
	<label>40178</label>
	<icon1>#newcommand</icon1>
	<function type="script">
		<instruction>@script JScript</instruction>
		<instruction>//  https://resource.dopus.com/t/rename-files-with-number-sequentially/40178</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.selected.count == 0) return;</instruction>
		<instruction />
		<instruction>    var item = tab.selected(0);</instruction>
		<instruction />
		<instruction>    var part1 = item.name_stem.replace(/(.*_)(\d+)/, &apos;$1&apos;);</instruction>
		<instruction>    var part2 = item.name_stem.replace(/(.*_)(\d+)/, &apos;$2&apos;);</instruction>
		<instruction />
		<instruction>    var cmdLine = (&apos;Rename ADVANCED PATTERN=&quot;&apos; + part1 + &apos;*&quot; TO=&quot;&apos; + part1 + &apos;[#]&quot; NUMBER=&apos; + part2);</instruction>
		<instruction>    // DOpus.Output(cmdLine);</instruction>
		<instruction>    cmd.RunCommand(cmdLine);</instruction>
		<instruction>}</instruction>
	</function>
</button>

How to use buttons and scripts from this forum

1 Like

Hello lxp,
Sorry for my ignorance but what should I do with this script.
Can you explain to me?

Follow the link above. Leo's post contains everything you need to know, right at the beginning.

In case you weren't aware, the last six digits are likely the time. For example: 204621 is probably 8:46:21 PM (8 PM, 46 minutes, 21 seconds). If you were already aware, then maybe this will be helpful to someone else.