Renaming Files within multiple folders

Advanced Renamer forum
#1 : 04/06-22 08:02
Golden Elixir
Golden Elixir
Posts: 2
Hello, I have several hundred folders with separate files inside them, and I would like to rename all of the files with the same batch method (<Inc Nr:1>).

I have tried doing this manually, selecting the files in each folder and renaming them, but it seems a bit too tedious and would require hours to do.

I was wondering if there is a script to do the same.


For clarity, I would like the name of the files within each folder to be renamed, but would like the folder names to be untouched.

I would like files of each folder to be renamed separately, since adding directories while renaming files renames all of them together, as in it renames them leading from 1-10000 whereas I want the names to be named separately for each folder, as would happen if I were to rename files in each folder manually.


04/06-22 08:02 - edited 04/06-22 08:10
#2 : 04/06-22 09:35
David Lee
David Lee
Posts: 1125
Use a Script method and define an object in the Pre-batch Script to keep count of how many files have been enumerated in each folder (works like an array indexed by the folder name):

var filesInFolder = {};

Then in the main script check if the object element corresponding to the item's folder name already exists. If not set it to 1, otherwise increment its value. For example the following code will append a space followed by an incrementing number, zero-padded to 3 digits, to each original filename.

folder = app.parseTags("<DirName:1>");
if(num = filesInFolder[folder]) num++; else num = 1;
filesInFolder[folder] = num;
return item.name + " " + ("00" + num).slice(-3);

In the return statement ("00" + num).slice(-3) zero-pads the incrementing number to 3 digits by prefixing 2 zero characters to the number and then keeping only the final 3 characters.



04/06-22 09:35
#3 : 04/06-22 13:48
Golden Elixir
Golden Elixir
Posts: 2
Reply to #2:
Thank you, this script works wonders!


04/06-22 13:48