Replace with Parent Folder Name At Position

A swapping-ground for Regular Expression syntax

Replace with Parent Folder Name At Position

Postby shiv » Mon Jul 22, 2019 1:50 pm

Hi All,
Please help to replace particular text in filename within a folder with its parent folder name.

example: Replacing "the" with parent folder names in the filenames.
C:\xander\shaun-of-the-dead.mp3

C:\cage\out-in-the-sun.mp3

output needed:
Shaun-of-xander-dead.mp3
out-in-cage-sun.mp3

This is not about append prefix or suffix, I think this task requires regex which I do not know very well.

many thanks!
shiv
 
Posts: 3
Joined: Mon Jul 22, 2019 1:40 pm

Re: Replace with Parent Folder Name At Position

Postby shiv » Mon Jul 22, 2019 1:53 pm

shiv wrote:Hi All,
Please help to replace particular text in filename within a folder with its parent folder name.

example: Replacing "the" with parent folder names in the filenames.
C:\xander\shaun-of-the-dead.mp3

C:\cage\out-in-the-sun.mp3

output needed:
shaun-of-xander-dead.mp3
out-in-cage-sun.mp3

This is not about append prefix or suffix, I think this task requires regex which I do not know very well.

many thanks!
shiv
 
Posts: 3
Joined: Mon Jul 22, 2019 1:40 pm

Re: Replace with Parent Folder Name At Position

Postby therube » Mon Jul 22, 2019 4:35 pm

JavaScript Renaming would do it.


Otherwise, thinking your only option would be to use 9:Append Folder Name.

Something along the lines of...

append the folder name, suffix, with some "unique" separator

Then once you have the folder name in the name, you can go back & use 1:RegEx.

Something along the lines of...

Code: Select all
Match:  (.*?)\sthe\s(.*?)uniqueseparator(.*)
Replace:  \1 \3 \2
therube
 
Posts: 1022
Joined: Mon Jan 18, 2016 6:23 pm

Re: Replace with Parent Folder Name At Position

Postby Admin » Tue Jul 23, 2019 12:55 am

If you have a commercial license for BRU we can help with a Javascript macro to di this, thanks
Admin
Site Admin
 
Posts: 2059
Joined: Tue Mar 08, 2005 8:39 pm

Re: Replace with Parent Folder Name At Position

Postby shiv » Fri Jul 17, 2020 11:17 pm

therube wrote:JavaScript Renaming would do it.
How to do this in JavaScript? Or can I create a BRU macro for this task?

Otherwise, thinking your only option would be to use 9:Append Folder Name.

Something along the lines of...

append the folder name, suffix, with some "unique" separator

Then once you have the folder name in the name, you can go back & use 1:RegEx.

Something along the lines of...

Code: Select all
Match:  (.*?)\sthe\s(.*?)uniqueseparator(.*)
Replace:  \1 \3 \2
shiv
 
Posts: 3
Joined: Mon Jul 22, 2019 1:40 pm


Return to Regular Expressions