Renaming with script method regex calculation within fi

A swapping-ground for Regular Expression syntax

Renaming with script method regex calculation within fi

Postby ddy313 » Mon Apr 27, 2020 10:42 pm

Renaming with script method regex calculation within filename string

i m looking for guidance on problem renaming files

i have got hundreds of filenames look like

aa-95865-00-bb.ext
aa-45732-00-bb.ext
aa-85855-00-bb.ext
aa-75263-00-bb.ext
aa-35165-00-bb.ext

i want to rename by replacing "00" with sum of five digits starting at index 4

eg "00" in the first filename to be replaced by 9+5+8+6+5 = 33, to be renamed as, aa-95865-33-bb.ext
"00" in the second filename to be replaced by 4+5+7+3+2 = 21, to be renamed as, aa-45732-21-bb.ext
and so on ..

please guide .. thanks ..
ddy313
 
Posts: 5
Joined: Mon Apr 27, 2020 10:20 pm

Re: Renaming with script method regex calculation within fi

Postby therube » Tue Apr 28, 2020 4:12 am

(Thinking you want JavaScript rather then RegEx.)

How/where are the sets of 5 digits coming from/being determined?
therube
 
Posts: 1314
Joined: Mon Jan 18, 2016 6:23 pm

Re: Renaming with script method regex calculation within fi

Postby Admin » Tue Apr 28, 2020 6:40 am

Hi, it can be done with a Javascript script if you have a commercial license. cheers
Admin
Site Admin
 
Posts: 2343
Joined: Tue Mar 08, 2005 8:39 pm

Re: Renaming with script method regex calculation within fi

Postby RegexNinja » Tue Apr 28, 2020 2:36 pm

Hi... Regex cant perform math, not with just 1-expression anyways.
If you have the commercial license, this can handle it.. Cheers.

#12Filters:
Mask=^[a-z]-\d{5}-00-.+
Regex=Checked
Folders=UnChecked
F5/Refresh to enforce the filters

Special / Javascript Renaming:
digits=name.substr(3,5).split('')
total=0
for(i=0; i<5; i++){total += parseInt(digits[i])}
newName=name.substr(0,9) + total + name.substr(11)

Results:
aa-45732-00-bb ---> aa-45732-21-bb
aa-95865-00-bb ---> aa-95865-33-bb
aa-9586b-00-bb ---> no effect (b gets filtered by #12Mask)
RegexNinja
 
Posts: 134
Joined: Fri Feb 21, 2020 5:26 pm

Re: Renaming with script method regex calculation within fi

Postby ddy313 » Tue Apr 28, 2020 11:32 pm

therube wrote:(Thinking you want JavaScript rather then RegEx.)

How/where are the sets of 5 digits coming from/being determined?



my reply

RegexNinja sir, every digit in the set of 5 digits, represent marks given by the user to the content of the file, out of 9 (0 to 9) on the basis of 5 criteria
the 2 digit sum total of those 5 digits will show the total marks..

can it be done in BRU ? please guide
thanks
ddy313
 
Posts: 5
Joined: Mon Apr 27, 2020 10:20 pm

Re: Renaming with script method regex calculation within fi

Postby ddy313 » Tue Apr 28, 2020 11:35 pm

Admin wrote:Hi, it can be done with a Javascript script if you have a commercial license. cheers



my reply ..

Admin sir, thanks a lot for your prompt response..
ddy313
 
Posts: 5
Joined: Mon Apr 27, 2020 10:20 pm

Re: Renaming with script method regex calculation within fi

Postby ddy313 » Tue Apr 28, 2020 11:41 pm

therube wrote:(Thinking you want JavaScript rather then RegEx.)

How/where are the sets of 5 digits coming from/being determined?


my reply..

therube sir,
every digit in the set of 5 digits, represent marks given by the user to the author of the article out of 9 (0 to 9) on the basis of 5 criteria
the 2 digit sum total of those 5 digits will show the total marks..

can it be done in BRU ? pl guide
thanks for your prompt response ..
ddy313
 
Posts: 5
Joined: Mon Apr 27, 2020 10:20 pm

Re: Renaming with script method regex calculation within fi

Postby ddy313 » Tue Apr 28, 2020 11:46 pm

RegexNinja wrote:Hi... Regex cant perform math, not with just 1-expression anyways.
If you have the commercial license, this can handle it.. Cheers.

#12Filters:
Mask=^[a-z]-\d{5}-00-.+
Regex=Checked
Folders=UnChecked
F5/Refresh to enforce the filters

Special / Javascript Renaming:
digits=name.substr(3,5).split('')
total=0
for(i=0; i<5; i++){total += parseInt(digits[i])}
newName=name.substr(0,9) + total + name.substr(11)

Results:
aa-45732-00-bb ---> aa-45732-21-bb
aa-95865-00-bb ---> aa-95865-33-bb
aa-9586b-00-bb ---> no effect (b gets filtered by #12Mask)



my reply ..

RegexNinja sir, thanks a lot for your prompt reply,
will it be possible in BRU, if not, is there any other Renamer app which can do, please guide
thanks again ..
ddy313
 
Posts: 5
Joined: Mon Apr 27, 2020 10:20 pm

Re: Renaming with script method regex calculation within fi

Postby RegexNinja » Wed Apr 29, 2020 7:52 am

First, let me apologize for a typo:

The #12Mask should be: ^[a-z]{2}-\d{5}-00-.+
In all the coloring/formatting, I seemed to have wiped-out the very important: {2}

I was trying to post a decent description on how everything works, but my notes just seemed to over-complicate it.
So I gave up on the notes, and posted it with just the coloring, etc.. Sorry about the typo.
I requested the permission to edit posts. No answer (dont wanna be part of some 'expert' group, just edit my posts).

And yes, it works fine, so long as you have the commercial license for javascript renaming.
If you need notes on how the javascript works, just let me know..
Cheers
RegexNinja
 
Posts: 134
Joined: Fri Feb 21, 2020 5:26 pm


Return to Regular Expressions