Renaming a file by specifying a name

Is it possible to quickly implement the following renaming operation in Directory Opus:
For the order in which the selected files are displayed, the order of the files is determined by the sorting method currently set in Directory Opus (e.g. by name, date, type, etc.).
The second file is named "Y002";
The fifth "R005";
The sixth "Z006";
The seventh "L007";
The eighth "H008";
The tenth "F010";
Eleventh "L011".
The names of the other documents remain unchanged.

Forgive me if this requirement seems silly, I do this frequently and would like to be able to do the above with the click of a button.

Try

// https://resource.dopus.com/t/renaming-a-file-by-specifying-a-name/49356

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

    cmd.deselect = false;

    cmd.Clear();
    cmd.AddLine('Rename FROM="' + tab.all(1) + '" TO=Y002');
    cmd.AddLine('Rename FROM="' + tab.all(4) + '" TO=R005');
    cmd.AddLine('Rename FROM="' + tab.all(5) + '" TO=Z006');
    cmd.AddLine('Rename FROM="' + tab.all(6) + '" TO=L007');
    cmd.AddLine('Rename FROM="' + tab.all(7) + '" TO=H008');
    cmd.AddLine('Rename FROM="' + tab.all(9) + '" TO=F010');
    cmd.AddLine('Rename FROM="' + tab.all(10) + '" TO=L011');
    cmd.Run();
}
XML
<?xml version="1.0"?>
<button backcol="none" display="label" textcol="none">
	<label>49356</label>
	<icon1>#newcommand</icon1>
	<function type="script">
		<instruction>@script JScript</instruction>
		<instruction>// https://resource.dopus.com/t/renaming-a-file-by-specifying-a-name/49356</instruction>
		<instruction />
		<instruction>function OnClick(clickData) {</instruction>
		<instruction>	var cmd = clickData.func.command;</instruction>
		<instruction>	var tab = clickData.func.sourcetab;</instruction>
		<instruction />
		<instruction>    cmd.deselect = false;</instruction>
		<instruction />
		<instruction>    cmd.Clear();</instruction>
		<instruction>    cmd.AddLine(&apos;Rename FROM=&quot;&apos; + tab.all(1) + &apos;&quot; TO=Y002&apos;);</instruction>
		<instruction>    cmd.AddLine(&apos;Rename FROM=&quot;&apos; + tab.all(4) + &apos;&quot; TO=R005&apos;);</instruction>
		<instruction>    cmd.AddLine(&apos;Rename FROM=&quot;&apos; + tab.all(5) + &apos;&quot; TO=Z006&apos;);</instruction>
		<instruction>    cmd.AddLine(&apos;Rename FROM=&quot;&apos; + tab.all(6) + &apos;&quot; TO=L007&apos;);</instruction>
		<instruction>    cmd.AddLine(&apos;Rename FROM=&quot;&apos; + tab.all(7) + &apos;&quot; TO=H008&apos;);</instruction>
		<instruction>    cmd.AddLine(&apos;Rename FROM=&quot;&apos; + tab.all(9) + &apos;&quot; TO=F010&apos;);</instruction>
		<instruction>    cmd.AddLine(&apos;Rename FROM=&quot;&apos; + tab.all(10) + &apos;&quot; TO=L011&apos;);</instruction>
		<instruction>    cmd.Run();</instruction>
		<instruction>}</instruction>
	</function>
</button>

How to use buttons and scripts from this forum

1 Like

Thanks lxp, your replies are always prompt and efficient.
Now there's a problem, the extension of the file is removed after renaming it

Try

// https://resource.dopus.com/t/renaming-a-file-by-specifying-a-name/49356

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

    cmd.deselect = false;

    cmd.Clear();
    cmd.AddLine('Rename IGNOREEXT FROM="' + tab.all(1) + '" TO=Y002');
    cmd.AddLine('Rename IGNOREEXT FROM="' + tab.all(4) + '" TO=R005');
    cmd.AddLine('Rename IGNOREEXT FROM="' + tab.all(5) + '" TO=Z006');
    cmd.AddLine('Rename IGNOREEXT FROM="' + tab.all(6) + '" TO=L007');
    cmd.AddLine('Rename IGNOREEXT FROM="' + tab.all(7) + '" TO=H008');
    cmd.AddLine('Rename IGNOREEXT FROM="' + tab.all(9) + '" TO=F010');
    cmd.AddLine('Rename IGNOREEXT FROM="' + tab.all(10) + '" TO=L011');
    cmd.Run();
}

Great. Everything looks so perfect.