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

**URL:** https://resource.dopus.com/t/script-to-delete-file-1-and-3-and-rename-file-2-if-all-3-files-are-selected/54245
**Category:** Help & Support
**Created:** [January 21, 2025, 6:41pm UTC](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-21T18:41:12Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Morbid](https://resource.dopus.com/letter_avatar_proxy/v4/letter/m/f475e1/32.png) [@Morbid](https://resource.dopus.com/u/Morbid)
#### Post date: [January 21, 2025, 6:41pm UTC](https://resource.dopus.com/t/script-to-delete-file-1-and-3-and-rename-file-2-if-all-3-files-are-selected/54245/1 "2025-01-21T18:41:12Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![lxp](https://resource.dopus.com/user_avatar/resource.dopus.com/lxp/32/33734_2.png) [@lxp](https://resource.dopus.com/u/lxp)
#### Post date: [January 21, 2025, 7:17pm UTC](https://resource.dopus.com/t/script-to-delete-file-1-and-3-and-rename-file-2-if-all-3-files-are-selected/54245/2 "2025-01-21T19:17:24Z")

</div>

Try this.

```javascript
// 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**
>
> ```plaintext
> <?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](https://resource.dopus.com/t/how-to-use-buttons-and-scripts-from-this-forum/3546)

---

<div class="post-metadata">

### Author: ![Morbid](https://resource.dopus.com/letter_avatar_proxy/v4/letter/m/f475e1/32.png) [@Morbid](https://resource.dopus.com/u/Morbid)
#### Post date: [January 21, 2025, 8:52pm UTC](https://resource.dopus.com/t/script-to-delete-file-1-and-3-and-rename-file-2-if-all-3-files-are-selected/54245/3 "2025-01-21T20:52:45Z")

</div>

Thank you very much! It worked like a charm! 🙃
