How to complex rename in increments?

Bulk Rename Utility How-To's

How to complex rename in increments?

Postby johnsbox » Mon Jul 08, 2024 7:34 pm

Hi,

I am new to this software and greatly appreciate anyone taking the time to read this.

I would like to know if it is possible to rename pictures say, every 4 pictures 1_a.JPG 1_b.JPG 1_c.JPG 1_d.JPG then the next four pics would be 2_a.JPG 2_b.JPG 2_c.JPG 2_d.JPG and so on. I've tried tinkering around with it but am totally confused.

Again, thank you for your time.

J
johnsbox
 
Posts: 3
Joined: Mon Jul 08, 2024 7:29 pm

Re: How to complex rename in increments?

Postby SMazTX » Tue Feb 18, 2025 12:03 pm

Please post a list of actual file names with their before and after names. That might help get some answers. I'm not sure I fully understand what you're trying to do.
SMazTX
 
Posts: 8
Joined: Mon Feb 21, 2022 2:01 pm

Re: How to complex rename in increments?

Postby johnsbox » Mon Feb 24, 2025 7:37 pm

Say I have 20 pictures I just took using a Canon Power Shot digital camera with removable storage. The camera automatically names each image IMG_4450.JPG, IMG_4451.JPG, IMG_4452.JPG and so on (these numbers are what I made up, the numbers it uses to name pics I think are based on date/time/consecutive order). The 20 pics I took are of 5 different cats, with each cat getting 4 pictures each. So my first kitty would be IMG_4450.JPG, IMG_4451.JPG, IMG_4452.JPG & IMG_4453.JPG. Then my second kitty would be IMG_4454_.JPG, IMG_4455.JPG and so on. Since every 4 pictures is a different cat, I want to know if it's possible to use Bulk Rename Utility to rename the pictures in increments of 4. So the first 4 pictures would be renamed this way:

IMG_4450.JPG would become 1.JPG
IMG_4451.JPG would become 1_a.JPG
IMG_4452.JPG would become 1_b.JPG
IMG_4453.JPG would become 1_c.JPG

Then the next 4 pics which are of the second cat would be renamed:

IMG_4454.JPG would become 2.JPG
IMG_4455.JPG would become 2_a.JPG
IMG_4456.JPG would become 2_b.JPG
IMG_4457.JPG would become 2_c.JPG

And so on, ad infinitum.

Is it possible with this software? If not, is there software in existence that is capable of this? Thank you so much for responding! I posted this 2 or 3 times in the past year and a half and you are the first person ever to reply.

:mrgreen:
johnsbox
 
Posts: 3
Joined: Mon Jul 08, 2024 7:29 pm

Re: How to complex rename in increments?

Postby TheGhost78 » Tue Feb 25, 2025 1:31 am

This would be a lot easier if the files were already sorted into separate folders per cat. You could simply prefix the file name with the folder name and then number them sequentially, or (my preference) prefix with the folder name and then suffix with with date and time the photograph was taken using " - %Y-%m-%d %H.%M.%S" in Auto Date (8), Custom, so that you have the chronology stored in the filename.

However, going back to your example, if there are always four photographs of each cat, you can do something that sort of groups them together. Select all the pictures, and in Numbering (10):
Mode: Prefix
Start: 1
Increment: 4
Pad: 3 or more, depending on how many files you have. (pad 3 is enough for 16 files, pad 4 is enough for 64 files, pad 5 is enough for 256 files, etc)
Type: base 4
Optionally, remove the original filename using Remove (5), First n = however many characters necessary.

This will give you files named:
0001
0011
0021
0031

0101
0111
0121
0131

0201
0211
0221
0231

0301
0311
0321
0331, etc
TheGhost78
 
Posts: 173
Joined: Fri Jul 19, 2024 11:25 am

Rename in groups

Postby Luuk » Wed Feb 26, 2025 12:24 am

Also, with Special(14)'s "Javascript" the script can look something like...

// Group size (27 max for a-z) since each group's 1st-name not suffixed...
group=4

// Determine suffix for 2nd-or-more names per group...
suffix = '_' + String.fromCharCode(95 + counter%group)
if (counter%group==0) suffix='_'+String.fromCharCode(95+group)

// Prefix all names per group identically, adding suffix to 2nd-or-more names per group...
if (counter%group!=1) {newName = Math.ceil(counter/group) + suffix}
else newName = Math.ceil(counter/group)


With group=4, new-names get invented like...
1
1_a
1_b
1_c
2
2_a
2_b
2_c
3
...
Luuk
 
Posts: 803
Joined: Fri Feb 21, 2020 10:58 pm

Re: How to complex rename in increments?

Postby Admin » Wed Feb 26, 2025 12:57 am

To append to existing filename as a suffix then can use += for newName, e.g. newName += Math.ceil(counter/group) + suffix
Admin
Site Admin
 
Posts: 2883
Joined: Tue Mar 08, 2005 8:39 pm

Re: How to complex rename in increments?

Postby Admin » Tue Mar 04, 2025 2:01 am

Code: Select all
// Output: ["1", "1_a", "1_b", "1_c", "2", "2_a", "2_b", "2_c", "3", "3_a"]
function getSequenceElement(n) {
  // Calculate the group number: each group has 4 items (base, _a, _b, _c)
  group = Math.floor((n - 1) / 4) + 1;
  // Determine the position within the group (0 means the base item)
  offset = (n - 1) % 4;
  result = String(group);
  // If offset > 0, add the appropriate letter suffix.
  if (offset > 0) {
    // Convert offset (1,2,3) to letters ('a','b','c')
    letter = String.fromCharCode('a'.charCodeAt(0) + offset - 1);
    result += '_' + letter;
  }
  return result;
}

newName = name + "_" + getSequenceElement(counter);
Admin
Site Admin
 
Posts: 2883
Joined: Tue Mar 08, 2005 8:39 pm

Re: How to complex rename in increments?

Postby Admin » Tue Mar 04, 2025 2:08 am

Alternative:

Code: Select all
function getSequenceElement(n, groupSize) {
  // Calculate the group number. For n=1..groupSize, group is 1; for n=groupSize+1..2*groupSize, group is 2, etc.
  const group = Math.floor((n - 1) / groupSize) + 1;

  // Calculate the position within the group (0-indexed)
  const indexWithinGroup = (n - 1) % groupSize;

  // Convert the index into a letter starting from 'a'.
  const letter = String.fromCharCode('a'.charCodeAt(0) + indexWithinGroup);

  // Return the string in the format "group_letter"
  return group + "_" + letter;
}

newName = name + "_" + getSequenceElement(counter,4);


Function Details
Group Calculation:
The group number is determined by (n - 1) / groupSize (using integer division) plus one. This ensures that positions 1 through groupSize belong to group 1, positions groupSize+1 through 2*groupSize belong to group 2, etc.
Index Within Group:
The remainder (n - 1) % groupSize gives a value from 0 up to groupSize - 1. This is used to determine which letter to append.
Letter Suffix:
The numeric index is converted into a letter by adding it to the character code for 'a'. For instance, 0 converts to 'a', 1 to 'b', and so on.
Customizability:
By changing the groupSize parameter, you can easily adjust how many items are in each group. For example, if you set groupSize to 5, the outputs will follow the sequence "1_a", "1_b", "1_c", "1_d", "1_e", "2_a", etc.

This function is flexible and can be used in various scenarios where you need to generate a patterned sequence string.
Admin
Site Admin
 
Posts: 2883
Joined: Tue Mar 08, 2005 8:39 pm


Return to How-To