JCDARK
February 27, 2024, 3:38pm
1
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.
lxp
February 27, 2024, 4:16pm
2
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('Rename FROM="' + tab.all(1) + '" TO=Y002');</instruction>
<instruction> cmd.AddLine('Rename FROM="' + tab.all(4) + '" TO=R005');</instruction>
<instruction> cmd.AddLine('Rename FROM="' + tab.all(5) + '" TO=Z006');</instruction>
<instruction> cmd.AddLine('Rename FROM="' + tab.all(6) + '" TO=L007');</instruction>
<instruction> cmd.AddLine('Rename FROM="' + tab.all(7) + '" TO=H008');</instruction>
<instruction> cmd.AddLine('Rename FROM="' + tab.all(9) + '" TO=F010');</instruction>
<instruction> cmd.AddLine('Rename FROM="' + tab.all(10) + '" TO=L011');</instruction>
<instruction> cmd.Run();</instruction>
<instruction>}</instruction>
</function>
</button>
How to use buttons and scripts from this forum
1 Like
JCDARK
February 28, 2024, 1:24am
3
Thanks lxp, your replies are always prompt and efficient.
Now there's a problem, the extension of the file is removed after renaming it
lxp
February 28, 2024, 5:42am
4
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();
}
JCDARK
February 28, 2024, 1:35pm
5
Great. Everything looks so perfect.