Script to delete file 1 and 3 and rename file 2 if all 3 files are selected?

Forgive me as i am barely know how to make a simple script for a button... But maybe someone can help?

I need a script to delete file 1 and 3 and rename file 2 (with an exported rename function, it looks like like Rename PRESET="preset name here") if all 3 files are selected. The order in which the operations are performed is not important.

Can someone help, please?

Try this.

// https://resource.dopus.com/t/script-to-delete-file-1-and-3-and-rename-file-2-if-all-3-files-are-selected/54245

// 2025-01-21

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

    if (tab.selected_files.count != 3) return;

    cmd.RemoveFile(tab.selected_files(1));
    cmd.RunCommand('Delete QUIET');

    cmd.ClearFiles();
    cmd.AddFile(tab.selected_files(1));
    cmd.RunCommand('Rename PRESET="preset name here"');
}
XML
<?xml version="1.0"?>
<button backcol="none" display="label" hotkey_label="yes" label_pos="right" textcol="none">
	<label>54245</label>
	<tip>script-to-delete-file-1-and-3-and-rename-file-2-if-all-3-files-are-selected</tip>
	<icon1>#script</icon1>
	<function type="script">
		<instruction>@script JScript</instruction>
		<instruction>// https://resource.dopus.com/t/script-to-delete-file-1-and-3-and-rename-file-2-if-all-3-files-are-selected/54245</instruction>
		<instruction />
		<instruction>// 2025-01-21</instruction>
		<instruction />
		<instruction>function OnClick(clickData) {</instruction>
		<instruction>    var cmd = clickData.func.command;</instruction>
		<instruction>    var tab = clickData.func.sourcetab;</instruction>
		<instruction />
		<instruction>    if (tab.selected_files.count != 3) return;</instruction>
		<instruction />
		<instruction>    cmd.RemoveFile(tab.selected_files(1));</instruction>
		<instruction>    cmd.RunCommand(&apos;Delete QUIET&apos;);</instruction>
		<instruction />
		<instruction>    cmd.ClearFiles();</instruction>
		<instruction>    cmd.AddFile(tab.selected_files(1));</instruction>
		<instruction>    cmd.RunCommand(&apos;Rename PRESET=&quot;preset name here&quot;&apos;);</instruction>
		<instruction>}</instruction>
	</function>
</button>

How to use buttons and scripts from this forum

2 Likes

Thank you very much! It worked like a charm! :upside_down_face: