Add arbitrary letters to the suffix

Bulk Rename Utility How-To's

Add arbitrary letters to the suffix

Postby Zambunny » Wed Jan 14, 2026 2:53 pm

Hello everyone.

I want to rename groups of 5 files.
I want to attach to the new names a dash - and five arbitary letters: R, F, I, M, E.

Example:
P0-000-0000-000-R
P0-000-0000-000-F
P0-000-0000-000-I
P0-000-0000-000-M
P0-000-0000-000-E


The question is: because the letters are non-sequential, is Javascript the only way how to do this? I work for a non-profit organization so buying licenses isn't always a straightforward matter. Plus, we need to use this program on at least 3 separate computers so we would need to buy 3 licenses..

My second question is: because the files are sequences of photos, is there a way to see the thumbnails in the renaming preview so I can be certain I am assigning the correct letter to the right image?

Thank you.
Zambunny
 
Posts: 1
Joined: Wed Jan 14, 2026 1:14 pm

Re: Add arbitrary letters to the suffix

Postby Admin » Thu Jan 15, 2026 12:54 am

- For a repeating, non-sequential 5-letter pattern (R,F,I,M,E) applied in groups, the easiest, most reliable method is to use the built-in JavaScript renaming engine (Special (14) -> Javascript Renaming). That lets you map by index (counter) and apply the letters in any arbitrary order.
- You can approximate it without JavaScript but it’s awkward and fragile (see notes below). JavaScript is the clean solution and it runs inside Bulk Rename Utility — no extra scripting tool needed.

Why JavaScript is best
- The JavaScript engine has a per-file counter (counter) and lets you do arithmetic and conditional logic, so you can compute counter % 5 and pick the letter R/F/I/M/E in whatever order you want.
- RegEx and Replace panels don’t support arithmetic or modular mapping inside replacements, so they can’t easily implement a repeating custom sequence without a lot of manual setup.

Example JavaScript to do this
1. Open Special (14) -> Javascript Renaming.
2. Paste this script and Preview (the script uses the provided variables from BRU):

[code]// map groups of 5 to letters R,F,I,M,E
var letters = ["R","F","I","M","E"];
// counter is the built-in 1-based index for each file
var idx = counter - 1; // make zero-based
var letter = letters[idx % 5]; // repeating sequence
newName = name + "-" + letter; // name is filename without extension
// leave newExt alone so extension is unchanged
[/code,

Notes:
- This produces Name-LETTER (keeps existing extension). Example: P0-000-0000-000 > P0-000-0000-000-R, etc.
- If you need the dash only for files that are exactly in groups of 5, or if you need to restart the cycle per-folder, you can adjust the script (e.g., use object("container") or setState/getState to reset per-folder).
- To preview, select the files in the list and use the Rename Preview (New Name column). If you like the preview, run Rename.

Non-JavaScript workaround (possible but clumsy)
- Append a short numeric counter (Numbering (10)) that increments 1..N.
- Use multiple Replace pairs (Replace (3) editor) to map numeric suffixes to letters, e.g. replace 1|6|11|16 with R, 2|7|12|17 with F, etc. This requires you to enumerate every number that will appear (or build many pairs) and is error-prone for large sets.
- So it’s possible but impractical for big sets or many folders.

Thumbnails / verifying which image gets which letter
- Bulk Rename Utility does not provide an image thumbnail pane in the renaming preview, but it provides a picture viewer (CTRL+W).
Admin
Site Admin
 
Posts: 3139
Joined: Tue Mar 08, 2005 8:39 pm

Re: Add arbitrary letters to the suffix

Postby Admin » Thu Jan 15, 2026 12:59 am

Below is a slightly more advanced JavaScript variant for Bulk Rename Utility. It:

- Applies the repeating custom sequence ["R","F","I","M","E"] in order.
- Skips directories.
- Keeps the extension unchanged.
- Maintains a per-folder counter so the 5-letter cycle restarts for each folder.
- Uses persistent state so the per-folder counter is stable for the batch.
- Uses askOnce to optionally accept a starting offset (one-time prompt).

Script (paste into Special (14) --> Javascript Renaming):

Code: Select all
// Advanced: per-folder repeating sequence R,F,I,M,E with optional start offset
// Letters sequence (edit order here if you wish)
var letters = ["R","F","I","M","E"];

// Skip directories (no renaming for folder entries)
if (object("isdir")) {
    newName = origName;
    newExt  = origExt;
    return;
}

// Ask once for an optional numeric start offset (0 = default)
var startOffsetStr = askOnce("Enter start offset (0 to start at first letter):", "0");
var startOffset = parseInt(startOffsetStr, 10);
if (isNaN(startOffset) || startOffset < 0) startOffset = 0;

// Per-folder counter state key
var folderPath = object("folder");           // full folder path
var stateKey = "cnt_for_" + folderPath;

// Initialize per-folder counter at first rename or when folder changes
// setStateAtStart not used because multiple folders may be processed in one batch
var current = getState(stateKey, null);
if (current === null) {
    // start at provided offset (so first file in folder uses offset+1)
    setState(stateKey, startOffset);
    current = startOffset;
}

// bump local counter and save
current = current + 1;
setState(stateKey, current);

// zero-based index into letters
var idx = (current - 1) % letters.length;
var letter = letters[idx];

// Build new name: existing base name + "-" + letter
newName = name + "-" + letter;
// preserve extension (explicitly)
newExt = ext;


Notes and tips
- To change the letter order or the group size, edit the letters array (e.g., ["A","B","C"]).
- This script restarts the cycle for each folder (useful when processing many folders). If you want a single continuous cycle across all folders, use a global state key that does not include folderPath.
- The askOnce prompt appears only once per batch; you can leave the default 0 to start at the first letter.
- Preview carefully: select the files you intend to rename and use the New Name column to check results. The script runs last in the pipeline (after other panels).
- If you need the cycle to restart on a change of some other property (e.g., when the filename prefix changes), you can replace folderPath with another key derived from object("container") or parts of name and reset the state accordingly.
Admin
Site Admin
 
Posts: 3139
Joined: Tue Mar 08, 2005 8:39 pm


Return to How-To