search csv and find match and rename

Bulk Rename Utility How-To's

search csv and find match and rename

Postby mschre » Sat May 31, 2025 2:40 pm

Hello,
I would like to rename image series using a csv.
The csv has the old name or parts of it and the new name.
The files to be renamed (image series) are in a folder and have the old name with a count at the end.
Example: Image-1.jpg, Image-2.jpg, Image-3.jpg...

The program should find the file "Image*" in the csv and then convert the files in the folder to 230000999-1.jpg (new name), 230000999-2.jpg, 230000999-3.jpg...as often as it finds "image". If it then finds "painting*", it converts it to 888000999-1.jpg...until it finds the next match.

I tried to import a test csv but was not successful. Error: "does not contain valid lines"
also I am not quite clear where to activate the count.

I hope the challenge is understandable.

Thank you very much

Marc
mschre
 
Posts: 3
Joined: Sat May 31, 2025 2:24 pm

Re: search csv and find match and rename

Postby Admin » Sun Jun 01, 2025 4:38 am

Please post a list of 10 names as an example before / after rename, and step-by-step instructions on how wanting to rename.
Admin
Site Admin
 
Posts: 2923
Joined: Tue Mar 08, 2005 8:39 pm

Re: search csv and find match and rename

Postby mschre » Mon Jun 02, 2025 3:28 pm

Hello,

the csv looks like this:

ArtNo old, ArtNo new

1-23723-44/402, 230400187
1-23774-43/001, 230000250
1-23779-45/001, 240000014
1-23781-45/597, 230500202
1-23786-45/805, 240800082

the Files in the folder looks like this:

001-23723-44-402-090.jpg
001-23723-44-402-270.jpg
001-23723-44-402-300.jpg
001-23723-44-402-BOT.jpg
001-23723-44-402-DT1.jpg
001-23723-44-402-TOP.jpg
001-23774-43-001-090.jpg
001-23774-43-001-270.jpg
001-23774-43-001-300.jpg
001-23774-43-001-BOT.jpg
001-23774-43-001-DT1.jpg
001-23774-43-001-TOP.jpg
001-23779-45-001-090.jpg
001-23779-45-001-270.jpg
001-23779-45-001-300.jpg
001-23779-45-001-BOT.jpg
001-23779-45-001-DT1.jpg
001-23779-45-001-MO1.jpg
001-23779-45-001-TOP.jpg
....

The result sholud look like this:

230400187-01.jpg
230400187-02.jpg
230400187-03.jpg
230400187-04.jpg
230400187-05.jpg
230400187-06.jpg
230000250-01.jpg
230000250-02.jpg
230000250-03.jpg
230000250-04.jpg
230000250-05.jpg
230000250-06.jpg
240000014-01.jpg
240000014-02.jpg
240000014-03.jpg
240000014-04.jpg
240000014-05.jpg
240000014-06.jpg

The programm sholud read the csv, und find a matching "ArtNo old" als name in the Filder und rename all the Files with the matching "ArtNo old" in the "ArtNo new" with an upcount for every matching file found.

Just three examples, but I hope the idea is clear.

best regards
Marc
mschre
 
Posts: 3
Joined: Sat May 31, 2025 2:24 pm

Re: search csv and find match and rename

Postby Admin » Tue Jun 03, 2025 5:36 am

Hi Marc,

the CSV also contains a / :

1-23723-44/402

Regardless I do not think BRU can do all of this fully automated.
How many lines in the CSV?
Admin
Site Admin
 
Posts: 2923
Joined: Tue Mar 08, 2005 8:39 pm

Re: search csv and find match and rename

Postby mschre » Tue Jun 03, 2025 7:32 am

Good Morning,

unfortunatly in this case yes it contains a "/", That one I could delete before running BRU, if it helps.

The csv has about 60 lines, but it will vary between 10 and 100. Not more.

Have a good day
Marc
mschre
 
Posts: 3
Joined: Sat May 31, 2025 2:24 pm

Re: search csv and find match and rename

Postby Admin » Tue Jun 03, 2025 8:25 am

You can try with Javascript.
I used the BRU assistant: https://www.bulkrenameutility.co.uk/js/

with

Code: Select all
I have these entries:

1-23723-44/402, 230400187
1-23774-43/001, 230000250
1-23779-45/001, 240000014
1-23781-45/597, 230500202
1-23786-45/805, 240800082

The Files in the folder looks like this:

001-23723-44-402-090.jpg
001-23723-44-402-270.jpg
001-23723-44-402-300.jpg
001-23723-44-402-BOT.jpg
001-23723-44-402-DT1.jpg
001-23723-44-402-TOP.jpg
001-23774-43-001-090.jpg
001-23774-43-001-270.jpg
001-23774-43-001-300.jpg
001-23774-43-001-BOT.jpg
001-23774-43-001-DT1.jpg
001-23774-43-001-TOP.jpg
001-23779-45-001-090.jpg
001-23779-45-001-270.jpg
001-23779-45-001-300.jpg
001-23779-45-001-BOT.jpg
001-23779-45-001-DT1.jpg
001-23779-45-001-MO1.jpg
001-23779-45-001-TOP.jpg
....

The result should look like this:

230400187-01.jpg
230400187-02.jpg
230400187-03.jpg
230400187-04.jpg
230400187-05.jpg
230400187-06.jpg
230000250-01.jpg
230000250-02.jpg
230000250-03.jpg
230000250-04.jpg
230000250-05.jpg
230000250-06.jpg
240000014-01.jpg
240000014-02.jpg
240000014-03.jpg
240000014-04.jpg
240000014-05.jpg
240000014-06.jpg


and its output was:

Code: Select all
// Transform name from: 001-23723-44-402-090.jpg
// To: 1-23723-44/402-090.jpg
// Explanation:
// - The first 3 digits (001) become the last group before the dash
// - The next groups (23723-44-402) become 23723-44/402
// - The leading 0 in the first group is removed (001 -> 1)
// - The format is: [first]-[second]-[third]/[fourth]-[rest]
// Example: name = "001-23723-44-402-090.jpg" => newName = "1-23723-44/402-090.jpg"

var m = name.match(/^(\d+)-(\d+)-(\d+)-(\d+)-(.*)$/);
if (m) {
  // m[1]=001, m[2]=23723, m[3]=44, m[4]=402, m[5]=090.jpg
  var first = String(Number(m[1])); // Remove leading zeros
  newName = first + '-' + m[2] + '-' + m[3] + '/' + m[4] + '-' + m[5];
}
// If not matching, newName is unchanged.
Admin
Site Admin
 
Posts: 2923
Joined: Tue Mar 08, 2005 8:39 pm


Return to How-To


cron