Renumbering & Deleting portion of file name - wildcard?

Bulk Rename Utility How-To's

Renumbering & Deleting portion of file name - wildcard?

Postby thestefanbunch » Thu Mar 04, 2021 2:32 am

I am working on a project whereby I am scanning my parents' old photos. Scans or the original image are assigned a 3 digit image #. I am also zooming in on portions of many of the images and rescanning zoomed in portion or scanning the backs (if they contain written notes). I have been renaming each with a letter at the end of the image # so the scans where I zoomed in or the backs of the images are connected to the original image by the b, c, d, etc. added to the end.
Ex: 101.jpg
101b.jpg
101c.jpg the next image might be 104.jpg, 104b.jpg, 105.jpg, etc. My scanner automatically assigns a # to each image but as I'm renaming them to add a b or c at the end, it leaves a lot of gaps in the numerical order of it all. Is there a way to rename them and keep the suffix of b, c, or other info I've added to the file name but remove all the gaps in #'s?

2nd question: I've figured out how to add a new numbering sequence as a prefix and have manually gone through and adjusted the file names which have the b, c, etc. in a couple of my folders because I don't know if there is another way to renumber and remove the gaps in sequence. I am now trying to figure out how to remove the old numbers in the filename. Because it's in a sequence, 001, 002, 005, 006, 010, etc., how do I tell it to delete a portion of the filename and only the 3#'s which follow it.
Ex: 001.album1_101_1936.jpg
002.album1_103_16x20.jpg
003.album1_107.jpg
003b.album1_107b.jpg
003c.album1_107c.jpg
I would like to remove the _101, _103, _107 portions of the middle of each file name, keeping the b, c, d, dates or any other info after those digits. Because many of the new file names also have a b or c after the new #, I cannot tell it to delete characters 11-14. In file names with a letter after the 3 digit image#, I would need to delete digits 12-15.

I don't understand how all the features work, so any guidance on this would be greatly appreciated. I could always go through and renumber/rename manually but I will likely make mistakes along the way and I have a few thousand photos to do.

thanks!
thestefanbunch
 
Posts: 3
Joined: Thu Mar 04, 2021 1:31 am

Re: Renumbering & Deleting portion of file name - wildcard?

Postby BogStandard » Thu Mar 04, 2021 6:04 pm

Answer to 2nd Question
BRU 3.4.2 or BRU 3.4.1

RegEx(1)
Match: (.*)(_)(\d{3})($|[^\d])(.*)
Replace: \1\4\5

Filters(12)
Mask: *.jpg
Folders: untick
Files: tick

Before
001.album1_101_1936.jpg
002.album1_103_16x20.jpg
003.album1_107.jpg
003b.album1_107b.jpg
003c.album1_107.jpg

After
001.album1_1936.jpg
002.album1_16x20.jpg
003.album1.jpg
003b.album1b.jpg
003c.album1.jpg

For the example set you have given this works, but do test it on a copy of your folder first.

Regards..
BogStandard
 
Posts: 17
Joined: Sun Feb 07, 2021 11:25 pm

Re: Renumbering & Deleting portion of file name - wildcard?

Postby thestefanbunch » Thu Mar 04, 2021 7:27 pm

Thank you for the reply. I did create a backup copy of my files last night so I have a copy to give this a try.

Am I typing everything you showed, exactly as is? As in everything after Match:, Replace:, Mask:, Folders:, and Files:?
RegEx(1)
Match: (.*)(_)(\d{3})($|[^\d])(.*)
Replace: \1\4\5

Filters(12)
Mask: *.jpg
Folders: untick
Files: tick

Could you please provide me with details of each step and what they mean so I could understand how to change this in future situations?
thestefanbunch
 
Posts: 3
Joined: Thu Mar 04, 2021 1:31 am

Re: Renumbering & Deleting portion of file name - wildcard?

Postby BogStandard » Thu Mar 04, 2021 11:05 pm

Short answer to:
"Am I typing everything you showed, exactly as is? As in everything after Match:, Replace:, Mask:, Folders:, and Files:?"
is Yes.

I suggest you first set: Display Options> Colours> Highlight Active Criteria
so when you enter any crieria the background fieldname (of RegEx(1) and Filters(12) in this case) will be flagged red.

Easy bit first is Filters(12).
The options here constrain the filteypes and whether foldernames and subfolders and their contents are included in the changes. I think of this as limiting the unintended changes I might cause.

The hard bit for me is
RegEx(1)
(.*)(_)(\d{3})($|[^\d])(.*)
Each group in the Match field that is surrounded by parenthesis () can be referred to in the Replace field by its position preceded by a backslash
\1\4\5

Group 1: All characters (.*)
before
Group 2: an underscore (_)
followed by
Group 3: three digits (\d{3})
followed by
Group 4: the end of the filename "$" OR "|" not a digit "[^\d]" so together ($|[^\d])
followed by
Group 5: All remaining characters (.*)

So IF the filename meets ALL the Match criteria we can use the parts to construct the new filename. In our example the new filename contains the contents of Groups 1, 4 and 5:
\1\4\5
which are
(.*)($|[^\d])(.*)
which leaves out the bit you didn't want
\2\3
(_)(\d{3})

Note that:
\d is shorthand for [0-9] and (\d{3}) for ([0-9][0-9][0-9])
(.*) means any or none

Hope this helps a bit. I would say it took me a while because my first attempts were around the simple
RegEx(1)
Match: (.*)(_\d{3})(.*)
Replace: \1\3
and if you try this pair you will see which filename in your example-set fails.

Another tip is, in a test folder, to create a dummy set of files (or copies) with the (full) variations in filenames you want to cover. And if your attempts don't work, no harm done. Which is what I did with yor example-set.

Regards..
BogStandard
 
Posts: 17
Joined: Sun Feb 07, 2021 11:25 pm

Re: Renumbering & Deleting portion of file name - wildcard?

Postby thestefanbunch » Fri Mar 05, 2021 1:05 am

Thanks again! I followed your instructions and it worked!

I greatly appreciate the detailed response. I will reread it a few times to process it all. It takes me back 30 years to my high school computer programming class....very little of which I remember!
thestefanbunch
 
Posts: 3
Joined: Thu Mar 04, 2021 1:31 am

Re: Renumbering & Deleting portion of file name - wildcard?

Postby Luuk » Fri Mar 05, 2021 5:52 am

This excellent RegEx(1) solutions! If you like to experiment and study the regexs, this to be another way...
(.+)_\d{3}($|\D.*)
\1\2

Its exactly like BogStandard's, but Im only just moving some groups and using "\D" to say "[^\d]".
The "\D" is saying "Not Number", so ($|\D.*) is saying "EndOfName" or "Anything that not starts with number".
We need more postings like this, because Im thinking the best way to learn is by practicing on the filenames.
Luuk
 
Posts: 691
Joined: Fri Feb 21, 2020 10:58 pm

Re: Renumbering & Deleting portion of file name - wildcard?

Postby Admin » Fri Mar 05, 2021 7:39 am

With javascript:

Code: Select all
var n = name.indexOf("_"); // find first _
if (n>0) newName = name.substr(0,n) + name.substr(n+4); // if found remove _ plus next 3 chars
Admin
Site Admin
 
Posts: 2343
Joined: Tue Mar 08, 2005 8:39 pm

Re: Renumbering & Deleting portion of file name - wildcard?

Postby BogStandard » Fri Mar 05, 2021 6:25 pm

Hi Luuk or Admin.

First thanks for the compliment Luuk.

Can you help me by explaining why my first attempt:
RegEx(1)
Match: (.*)(_\d{3})(.*)
Replace: \1\3
produces

Before:
a) 001.album1_101_1936
b) 001.album1_101_1936_222
c) 001.album1_101_1936_222_1234
d) 001.album1_101_1936_222_1234_333

After:
a) 001.album1_1016
b) 001.album1_101_1936
c) 001.album1_101_1936_1234
d) 001.album1_101_1936_222_1234

I was expecting RegEx to work Left to Right so for (_\d{3}) to catch the FIRST matching occurance but it always skips it.

Regards..
BogStandard
 
Posts: 17
Joined: Sun Feb 07, 2021 11:25 pm

Re: Renumbering & Deleting portion of file name - wildcard?

Postby BogStandard » Fri Mar 05, 2021 9:12 pm

OK. I have found out.
Although I don't fully understand yet it is to do with Greedy and Lazy.
See BRU Operations Manual vol 1 by Tim Mongeon

This works...
RegEx(1)
Match: (.*?)_\d{3}(.*)
Replace: \1\2

Before:
001.album1_101_1936.jpg
001.album1_101_1936_222.jpg
001.album1_101_1936_222_1234.jpg
001.album1_101_1936_222_1234_333.jpg
002.album1_103_16x20.jpg
003.album1_107.jpg
003b.album1_107b.jpg
003c.album1_107.jpg

After:
001.album1_1936.jpg
001.album1_1936_222.jpg
001.album1_1936_222_1234.jpg
001.album1_1936_222_1234_333.jpg
002.album1_16x20.jpg
003.album1.jpg
003b.album1b.jpg
003c.album1.jpg
BogStandard
 
Posts: 17
Joined: Sun Feb 07, 2021 11:25 pm


Return to How-To