#1 2019-10-15 04:35

brianwoody
Member
Registered: 2019-10-15
Posts: 2

Add part of original filename to new filename

I have a number of files to rename but cant work out how to do it.

This is a basic filename of this format:

900226_1.jpg

I want to rename to :

bldg_photo^226^1^900226_1.jpg   (i.e. "bldg_photo^" + last 3 digits before the underscore from original filename + "^1^" + original filename)

I have created some insert rules for some fixed values and i get this so far:

bldg_photo^XXX^1^900226_1.jpg

But i cant work out how to add the values in XXX above. These values in the example are 226 and are always the last 3 digits in the original filename before the _1.jpg

Any ideas on how to add the 3 digits??

Offline

#2 2019-10-15 05:20

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,440

Re: Add part of original filename to new filename

You need to use the Regular Expressions rule to extract those 3 digits.

Like follows:
1) Insert: Insert "^1^" as Prefix (skip extension)
2) Regular Expressions: Replace expression "\A(.*\d+(\d{3})_\d+)\Z" with "$2$1" (skip extension)
3) Insert: Insert "bldg_photo^" as Prefix (skip extension)

User manual for the Regular Expressions rule:
https://www.den4b.com/wiki/ReNamer:Regular_Expressions

Here is a demo of these rules in action:
brianwoody-topic-2557.png

Offline

#3 2019-10-15 08:55

brianwoody
Member
Registered: 2019-10-15
Posts: 2

Re: Add part of original filename to new filename

Awesome -  that works!!!
thanks for the very quick response

Offline

#4 2019-10-19 21:24

eR@SeR
Senior Member
From: Земун, Србија
Registered: 2008-01-23
Posts: 354

Re: Add part of original filename to new filename

Hi brianwoody,

If you need to add last one or more digits to the X part in "^226^X^" and if there are more than 3 digits before "226" part in "XXXX226_1", it will find matches and add last 3 digits properly. You can try this RegEx:

1) Regular Expressions: Replace expression  "(\d{3,}?(\d{3})_(\d+))" with "bldg_photo^$2^$3^$1" (skip extension)

If last digit is always "1" in your case, it will be always added in X part.

Check some examples:

Before:

900226_1.jpg
900227_1.jpg
900228_2.jpg
900229_3.jpg
900230_10.jpg
900231_123.jpg
9000232_1.jpg
900000233_1234.jpg

After:

bldg_photo^226^1^900226_1.jpg
bldg_photo^227^1^900227_1.jpg
bldg_photo^228^2^900228_2.jpg
bldg_photo^229^3^900229_3.jpg
bldg_photo^230^10^900230_10.jpg
bldg_photo^231^123^900231_123.jpg
bldg_photo^232^1^9000232_1.jpg
bldg_photo^233^1234^900000233_1234.jpg


TRUTH, FREEDOM, JUSTICE and FATHERLAND are the highest morale values which human is born, lives and dies for!

Offline

Board footer

Powered by FluxBB