Rename files by adding part of folder name

Bulk Rename Utility How-To's

Re: Rename files by adding part of folder name

Postby Admin » Sun Aug 03, 2025 1:05 am

Hi, paste the original script that is working and the new requirements here: https://bulkrename.software/js/
cheers
Admin
Site Admin
 
Posts: 3065
Joined: Tue Mar 08, 2005 8:39 pm

Re: Rename files by adding part of folder name

Postby MrMix » Mon Aug 04, 2025 12:55 pm

Hello and thank you for your reply.
I don't know how but I succeeded to get what I wanted :shock:
I modified the last row
Admin wrote:
Code: Select all
newName = prefix + album + " - " + rest;

into
newName = prefix + album + "_"+ object("container") + " - " + rest;

Now if I have files into a main folder the first script is working fine,
if I have files into a sub folder the second script is working fine but not vice versa.
Would it be possible to create only one script able to understand if files are into
the main folder (use first script) and/or if files are into sub folder (use second script) ?

Thanks & regards
MM
MrMix
 
Posts: 13
Joined: Thu Mar 09, 2023 5:55 pm

Re: Rename files by adding part of folder name

Postby Admin » Tue Aug 05, 2025 3:56 am

That's nice! Great that it's working now.

How would the combined script know if the files are in the main folder or a sub-folder? If that is known then the last line can be modified conditionally with an if statement.
Admin
Site Admin
 
Posts: 3065
Joined: Tue Mar 08, 2005 8:39 pm

Re: Rename files by adding part of folder name

Postby MrMix » Thu Aug 07, 2025 4:47 pm

Admin wrote:How would the combined script know if the files are in the main folder or a sub-folder? If that is known then the last line can be modified conditionally with an if statement.

Good question but I don't have the answer ! At the moment I'll stay with two scripts.
Regards
MM
MrMix
 
Posts: 13
Joined: Thu Mar 09, 2023 5:55 pm

Re: Rename files by adding part of folder name

Postby Ace_boy2786 » Thu Sep 04, 2025 8:08 pm

Hi everyone, Question, is there a way to do this in the GUI as I am completely lost trying to read this thread trying to accomplish something similar.

I am trying to take "V:\Folder1\Folder2\Ch.[001.x-999.x]\pg.[01-99].jpg" to be "V:\Folder1\Folder2\Ch.[001.x-999.x]\NewFileName (in saved config) - ch[001.x-999.x] - pg0[01-99].jpg".
This text should drop the "alpha characters" and just retain the numeric, as the alpha could differ between parent folders
this text doesn't change from original file

My current (and VERY time consuming) way of doing this is using the GUI (of BRU 3.4.4.0) is to open my saved naming scheme for selected files, then in the "add (07)" field make/update the naming scheme I want then go through the file tree into each "ch[001-999]" folder manually changing the new number then apply, then select the next folder and change the number again and click apply, rinse and repeat... I've done this this way since I discovered this program (which is a godsend since it has speed up my renaming ability drastically as is) but I'm currently about 200 folders into a set of files that has 900+ folders to rename the contents of.

If I could figure out how to "automate" this (I would tell it when to run) it would be better than a godsend.... Have it scan folder1 then each sub-folder (folder2[a-z]) would reference a saved config for name and structure using folder3 for "ch##", and output as above for each "folder 2[a-z]"
Ace_boy2786
 
Posts: 1
Joined: Thu Sep 04, 2025 7:19 pm

Re: Rename files by adding part of folder name

Postby Admin » Fri Sep 05, 2025 12:02 am

// Example before: full path “V:\Folder1\Folder2\Ch.[001.x-999.x]\pg.5.jpg”
// name == "pg.5", object("container") == "Ch.[001.x-999.x]"
// Desired new filename (no extension): “NewFileName (in saved config) - Ch.[001.x-999.x] - pg003”

// get the chapter folder name
var chapter = object("container");
// extract the numeric page index from the original name (e.g. "pg.5">? "5")
var pageMatch = name.match(/^pg\.?(\d+)$/i);
var rawPage = pageMatch ? pageMatch[1] : name;
// pad to two digits then prefix a zero to make three digits (e.g. "5" > "005", "12" > "012")
var padded = "0" + padNum(rawPage, 2);
// construct the new name
newName = "NewFileName (in saved config) - " + chapter + " - pg" + padded;

Post more examples before / after names for more accuracy in the script.
Admin
Site Admin
 
Posts: 3065
Joined: Tue Mar 08, 2005 8:39 pm

Previous

Return to How-To