Renaming every multiple of 9?

After some work I managed to get an image editor to clip all the player card images from a pdf I have, but now the files are not showing the cards in sequential order. I determined that I need to renumber all nine of the first 9 cards and every multiple of those original card numbers. For example, I have the card numbered 9 that needs to be numbered 1, but 18, 27, 36, etc. all need to be reduced by 8 as well. in order to put them in the sequential order I want to have them displayed in when I sort them by name, but I can not figure out how to do it and it's driving me nuts!
Welcome David!

I'm sure what you want is doable but you need to provide better details. The exact scheme you desire is not clear.

EG do you want:
Orig   Opt A   Opt B
 1         1       1
 2         2       2
 3         3       3
 4         4       4
 5         5       5
 6         6       6
 7         7       7
 8         8       8
 9         1       1
10        2      10
11        3      11
12        4      12
13        5      13
14        6      14
15        7      15
16        8      16
17        9      17
18       10      10
19       11      19
20       12      20
21       13      21
22       14      22
23       15      23
24       16      24
25       17      25
26       18      26
27       19      19

1 -- Or several files all named 1 thru 8?      Or something completely different?

2 -- Are there other numbers besides the number?

3 -- What is the text before and after the number?

4 -- How do you intend to handle duplicate filenames?

Please provide **exact** before and after filenames that you want.

Regards,
Randy
Reply to #2:
There is a grid of 3 by 3 cards on every page. These cards were clipped using an image editor (with a bit of creativity and a special user added plugin) but the end result was each card being saved out of the original order. The numbered order I want is the usual one starting with the upper left and continuing to the right before dropping down to the next row and continuing from left to right again. But what I got was each page following this pattern:
Left in the middle row (should be the 4th but is the 1st)
Middle in the lower row (should be the 7th but is the 2nd)
Right in the middle row (should be the 6th but is the 3rd)
Middle in the middle row (should be the 5th but is the 4th)
Right in the upper row (should be the 3rd but is the 5th)
Right in the lower row (should be the 9th but is the 6th)
Middle in the upper row (should be the 2nd but is the 7th)
Lower left in the lower row (should be the 7th but is the 8th)
Left in the upper row (should be the 1st but is the 9th)

Order they should be in
123456789
Order they are in
476539271

As for the exact before and after file names, I don't care. So long as sorting the files by name makes them show up correctly. If you are talking about writing a script for me then... well first of all thankyou! In that case I can rename them to match it before I run it. They already have their incorrect sequential numbers assigned to them.
Reply to #3:

Suppose you have 3 pages of cards, that's 27 images. They are not all 27 named one of {476539271}.
If each file does appear in Aren -- in that order -- when you have 27+ files loaded in Aren, we can work with that. But it seems highly improbable and certainly isn't true for the last page if it has less than 9 cards.

Note also that 7 appears twice in that list!   You are omitting and misstating crucial details!

(A) Are the files in a consistent order, across *EVERY SINGLE PAGE AND FILE*?
If so how? Sorted by name? Date?

In order to rename the files, we need still need more information than you are providing.

So either confirm (A) or
(B). . .
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
====> PROVIDE **EXACT** BEFORE AND AFTER FILENAMES THAT YOU WANT. <====
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
For at least three pages of cards.
Reply to #4:
Strictly for my own amusement, here's how you can rename files that are in an arbitrary but absolutely consistent order** :

//-------------------------------------------------------
// "function( index, item)" script
//-------------------------------------------------------
const cFilesPerPage = 9;
const cFileOrderOnPageStr = "476539281";
const cFileOrderOnPage = [...new Set ( cFileOrderOnPageStr.split (/(\d)/).filter (d => /\d/.test(d) ) ) ];
if (cFileOrderOnPage.length !== cFilesPerPage) throw ("Invalid File-order scheme");

//--- Assume that all files are shown/listed, in Aren, in the fixed order of cFileOrderOnPageStr
//-- Note that index is zero-based here but 1 based in the file list.
let pageNum = Math.floor (index / cFilesPerPage) + 1;
let targIndex = cFileOrderOnPage [ index % cFilesPerPage ];
let newName = `Page ${String (pageNum).padStart (3, "0")} Card ${targIndex}`;

return newName;

//-------------------------------------------------------


** As shown in the Aren file list.
Reply to #4:
A, by name.

You're right about the 7, I did make a typo and accidentally copied it to the later part of my post. Sorry. The first 7 is supposed to be an 8. And as unlikely as it sounds there really are 9 cards on the last page and every other page. I actually have a total of 270 cards. As for the name, I'll just leave the number. They will start with 001.png and end with 270.png, increasing their number sequentially.

So, the incorrect order the first 9 files are in, as well as the pattern every following 9 cards are in, is actually 486539271. And the name of each card is just a number and file extension. 001.png to 270.png.
Reply to #6:

Whelp, you can't straight rename 270 files to the exact same names but different. It's a classic A/B swap problem and Aren doesn't supply a convenient C. ;)

So, the script will set the correct new numbers but it will have to put an "n " in front of them to avoid Aren freaking out.

1) Create a new script method ( https://www.advancedrenamer.com/user_guide/v4/method_script ).

2) Then paste the following code in the "function(index, item)" block and apply it.
*** Be sure to overwrite/replace anything that was in that input before. ***

//-------------------------------------------------------
// "function( index, item)" script
//-------------------------------------------------------
const cFilesPerPage = 9;
const cFileOrderOnPageStr = "486539271";
const cFileOrderOnPage = [...new Set ( cFileOrderOnPageStr.split (/(\d)/).filter (d => /\d/.test(d) ) ) ];
if (cFileOrderOnPage.length !== cFilesPerPage) throw ("Invalid File-order scheme");

//--- Assume that all files are shown/listed, in Aren, in the fixed order of cFileOrderOnPageStr
//-- Note that index is zero-based here but 1 based in the file list.
let pageIdx = Math.floor (index / cFilesPerPage);
let targIndex = Number (cFileOrderOnPage [ index % cFilesPerPage ] );
let newFileNum = targIndex + pageIdx * cFilesPerPage;
let newName = `n ${String (newFileNum).padStart (3, "0")}`;

return newName;

//-------------------------------------------------------


To use, make sure that the 270 files in Aren's list are in order by "Filename" (they usually are by default). Click on the column header to change the sort.

This script doesn't use the old filename(number) it just cares about what order the files are shown in Aren's file list.

You should see something like this in Arens' filelist:

Filename  |  New Filename
001.png   |   n 004.png
002.png   |   n 008.png
003.png   |   n 006.png
004.png   |   n 005.png
005.png   |   n 003.png
006.png   |   n 009.png
007.png   |   n 002.png
008.png   |   n 007.png
009.png   |   n 001.png
010.png   |   n 013.png
011.png   |   n 017.png
etc.

Run the batch and then do any extra renaming separately.

Good luck,
Randy

Reply to #7:

Hi guys,
Some other ways to get'er done:

1) "Hillbilly" javascript:

cardSeq = "476539281" ; seqLen = 9 ;
page = Math.floor( ( item.name - 1 ) / seqLen ) ;
ins = index - ( page * 9 ) ;
return "p" + ( page + 1 ) + "c" + cardSeq[ins] ;

(Doesn't work unless the filename is just a sequence number, but that wouldn't be hard to change)

...or...OR...OOORRRR... 2) Here's the one I like: one New Name method and one line of code.

New name:
c<switch:4:7:6:5:3:9:2:8:1>
Script:
return "p" + ( Math.floor( index / 9 ) + 1 ) + item.newBasename ;

This way works no matter what the filename is. The cards just have to be in the right sequence.

3) OK, this next one is just showing off. This is just the New Name method toted over to JS. So, even "hillbilly-er" JS (but only one line of it :)

return "p" + (Math.floor(index/9) + 1 )+app.parseTags('c<switch:4:7:6:5:3:9:2:8:1>');

Again, works with any filename, as long as the files are in the right sequence.

All this is just to demonstrate the flexibility and power of ARen. Obviously Randy's code works perfectly; that's what he does. But there are almost always several ways to do something in Advanced Renamer.

Best,
DF