possible to read a value from filnam and reuse?

Post any general comments regarding Bulk Rename Utility here. Open to all registered users.

possible to read a value from filnam and reuse?

Postby drothman66 » Fri Jun 07, 2013 3:27 pm

i was wondering if it's possible to recurse (only about 10000 files, so not near the 250,000 mentioned in the doc) thru directories and make the following change:

for each file where filename = "*_0??" , rename the file to <stuff before the "_" followed by " (??)" (where ?? is an integer and stripped of any leading zeros)

for examples:
File10203_001.txt to "File10203 (1).txt"
pic20030201_022.jpg" to "pic20030201 (22).jpg"

thanks
drothman66
 
Posts: 5
Joined: Fri Jun 07, 2013 3:17 pm

remove underscore and leading zeros reuse digits numbers

Postby Stefan » Fri Jun 07, 2013 6:31 pm

FROM:
File10203_001.txt
File10204_004.txt
File10_222_201.txt
pic200302333_082.jpg
pic200305_502.jpg
pic_20030201_022.jpg

TO:
File10203 (1).txt
File10204 (4).txt
File10_222 (201).txt
pic200302333 (82).jpg
pic200305 (502).jpg
pic_20030201 (22).jpg

Rule:
Match 1:(everything greedy) till 2:(last underscore followed by none-or-more zeros) and 3:(one-or-more digits).
Drop underscore and leading zeros and put remaining number into parentheses.
Store first match into backreference group "\1", don't store second match as we drop it anyway, store third match into group "\2"
Replace with what is matched in group \1, add space and parentheses yourself, then add what was matched in group \2.


TRY:
RegEx(1)
Match: '(.+)_0*(\d+)'
Repla: '\1 (\2)'


Note:
Don't use the single quotes in real.
Test always with copies of your real files and be sure to have a backup.

.
Stefan
 
Posts: 736
Joined: Fri Mar 11, 2005 7:46 pm
Location: Germany, EU

Re: possible to read a value from filnam and reuse?

Postby drothman66 » Tue Jun 11, 2013 6:16 pm

thanks for this. i will play with it today or tomorrow. this is a much better solution than something i might have hacked together in perl.
drothman66
 
Posts: 5
Joined: Fri Jun 07, 2013 3:17 pm


Return to General Comments


cron