#1 2018-12-08 13:37

BadDogTitan
Member
Registered: 2018-12-08
Posts: 8

Add brackets around a variable length text at variable position?

I have filenames like this:

2018 12 02 - Quarterly Report A2.pdf
DOE, John - 2018 11 30 - Sales Statistics A33.pdf
DOE, Janet - 2018 04 02 - Products Recieved By Vendor A122 - Duplicate.xls
etc....

I need to put brackets around the 'A' numbers, and cannot figure out the logic.

I have thousands of files to rename....please help!

Thanks.

Offline

#2 2018-12-08 14:41

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

Re: Add brackets around a variable length text at variable position?

This kind of problem requires pattern matching, which can be achieved with either Regular Expressions or Pascal Script rule.

The following regular expression will do the job:

Expression: \b(A\d+)
Replace: ($1)

Input names:

2018 12 02 - Quarterly Report A2.pdf
DOE, John - 2018 11 30 - Sales Statistics A33.pdf
DOE, Janet - 2018 04 02 - Products Recieved By Vendor A122 - Duplicate.xls

Output names:

2018 12 02 - Quarterly Report (A2).pdf
DOE, John - 2018 11 30 - Sales Statistics (A33).pdf
DOE, Janet - 2018 04 02 - Products Recieved By Vendor (A122) - Duplicate.xls

Here is the documentation for the regular expressions:
http://www.den4b.com/wiki/ReNamer:Regular_Expressions

Offline

#3 2018-12-08 18:55

BadDogTitan
Member
Registered: 2018-12-08
Posts: 8

Re: Add brackets around a variable length text at variable position?

That works perfectly, den4b. Thanks!

I manually renamed a bunch of files prior to your response. Other than unmarking the individual files, is there a way to incorporate ignoring already bracketed files using the regular expressions so I don't end up with double brackets?

Offline

#4 2018-12-08 20:40

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

Re: Add brackets around a variable length text at variable position?

BadDogTitan wrote:

is there a way to incorporate ignoring already bracketed files using the regular expressions so I don't end up with double brackets?

Yes, but the expression will get a bit more complicated:

Expression: (\A|[^(])\b(A\d+)
Replace: $1($2)

Alternatively, you can use a Replace rule to replace double brackets "((" and "))" with a single bracket "(" and ")".

Offline

#5 2018-12-08 21:03

BadDogTitan
Member
Registered: 2018-12-08
Posts: 8

Re: Add brackets around a variable length text at variable position?

Thanks, again, den4b. I must say that I am most impressed with your utility, and your quick response. So much so, that I am going to purchase your software right now! Thanks, again.

Offline

Board footer

Powered by FluxBB