how to pull out certain parts of a filename and rename it

Bulk Rename Utility How-To's

how to pull out certain parts of a filename and rename it

Postby jg1067 » Mon Sep 21, 2020 5:53 pm

I have files where I need to pull out certain bits of information from the _ delimited filenames.

For example here are a few files I have that are named as follows:

BHE1Brd_GROCERY_1_09-20-2020_0_News-C_B_F_001_4_BHEXX_08132020113452.pdf
BHE1Tab_SPECIALTAB_1_09-20-2020_0_Features-C_B_A_001_4_BHEXX_08132020133258.pdf
SNL1Brd_SUNCLASS_1_04-19-2020_0_Production-B_B_G_003_4_SNLXX_04172020155143.pdf
BHE1Tab_TVBOOK_1_09-20-2020_0_Features-C_B_T_004_4_BHEXX_08132020133258.pdf

Based on the first filename listed above in the listed examples, I need to extract the following fields from the filename and make into a new filename for each file:

1. Pull out the date in the filename (e.g. 09-20-2020 and 04-19-2020) in the examples above and make the date appear as MMDDYY as the first part of the new filename.
2. Next, pull out the first 3 characters in the filenames above and tack that onto the end of the new filename currently containing MMDDYY date from step 1 above. (e.g. 092020BHE)
3. Next "hard code" DLY1ST onto the end of the filename and tack that onto the new filename we are building (e.g. 092020BHEDLY1ST)
4. Next, extract the "F" that is in bold and tack that onto the end of the new filename we are building (e.g. 092020BHEDLY1STF)
5 Lastly, grab the "001" that is in bold, strip off the first digit of the 3 digits and append that to the end of the filename we are building (e.g. 092020BHEDLY1STF01 )

So, based on the first filename example above, we would rename that file 092020BHEDLY1STF01.pdf

Any help you could provide would be greatly appreciated! I will be doing this from the command line version of the Bulk Rename utility. Thank you!
jg1067
 
Posts: 3
Joined: Mon Sep 21, 2020 5:30 pm

Re: how to pull out certain parts of a filename and rename it

Postby jg1067 » Mon Sep 21, 2020 8:24 pm

If I could just figure out how to pull the date from the middle of the filename and paste it to the front of the filename, I believe I can do everything else I need to do.

In the example BHE1Brd_GROCERY_1_09-20-2020_0_News-C_B_F_001_4_BHEXX_08132020113452.pdf ,
if I could grab "09-20-2020" and paste it to the beginning of the filename, that would be a huge help. I think I can figure out the rest of what I am needing to do.

Thank you.
jg1067
 
Posts: 3
Joined: Mon Sep 21, 2020 5:30 pm

Re: how to pull out certain parts of a filename and rename it

Postby Admin » Tue Sep 22, 2020 1:14 am

Try this RegEx (1)

Match: (.*)_(\d\d)-(\d\d)-(\d\d\d\d)_(.*)
Replace: \2-\3-\4_\1_\5
Admin
Site Admin
 
Posts: 2343
Joined: Tue Mar 08, 2005 8:39 pm

Re: how to pull out certain parts of a filename and rename it

Postby jg1067 » Tue Sep 22, 2020 4:04 pm

That worked! Thank you!!
jg1067
 
Posts: 3
Joined: Mon Sep 21, 2020 5:30 pm

Re: how to pull out certain parts of a filename and rename it

Postby LAOMUSIC ARTS » Tue Mar 21, 2023 12:22 am

Hi!
In my case, >i have pics with weird random synbols like:

R_1d1fdff1fe0247f79b924b1d624da460_bus_interior_body_bump.1008.jpeg
R_5c29a6a9006340479914c38b440fbf84_bus_dno_spec.1007.jpeg
etc...., every time different.


Any clue?

Thanks for any help!


LAO
LAOMUSIC ARTS
 
Posts: 1
Joined: Tue Dec 31, 2019 9:11 am

Re: how to pull out certain parts of a filename and rename it

Postby Admin » Tue Mar 21, 2023 5:45 am

Hi, what are the file names required before and after? thanks
Admin
Site Admin
 
Posts: 2343
Joined: Tue Mar 08, 2005 8:39 pm


Return to How-To