Calculations

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

Calculations

Postby regularexpress » Sun May 12, 2013 11:48 pm

Sorry if this isn't the right place to make this question, and I don't know much about Regular Expressions (willing to learn though if it's helpful). So, can I make calculations (addition, multiplication, etc) considering a file's name?

For example, the file is:
Aircraft [200 by 10].txt

I want the result as:
20 ~ Aircraft [200 by 10].txt

Is this possible?

Thanks for the attention!
regularexpress
 
Posts: 4
Joined: Sun May 12, 2013 10:10 pm

Re: Calculations

Postby Stefan » Mon May 13, 2013 7:29 pm

No calculations possible. You will need a renamer with scripting support like den4b ReNamer.

FROM:
Aircraft [200 by 10].txt
Aircraft [200 by 4].txt
Aircraft [200 by 8].txt
TO:
20 ~ Aircraft [200 by 10].txt
50 ~ Aircraft [200 by 4].txt
25 ~ Aircraft [200 by 8].txt
USE den4b ReNamer:
Code: Select all
var
SubPatterns: TStringsArray;
Begin
   SubPatterns:=SubMatchesRegEx(WideExtractBaseName(FileName),'(.*?)\[(\d+) by (\d+)\]',false);
   if Length(SubPatterns) <=0 then exit;
   FileName := IntToStr(StrToInt(SubPatterns[1]) / StrToInt(SubPatterns[2]))
       + ' ~ ' + WideExtractBaseName(FileName) + WideExtractFileExt(FileName);
End.
Stefan
 
Posts: 736
Joined: Fri Mar 11, 2005 7:46 pm
Location: Germany, EU

Re: Calculations

Postby regularexpress » Thu May 16, 2013 12:00 am

THANK YOU VERY MUCH.

I LOVE YOU.
regularexpress
 
Posts: 4
Joined: Sun May 12, 2013 10:10 pm

Re: Calculations

Postby Stefan » Thu May 16, 2013 11:10 am

I miss three exclamation marks at least after the second statement. :D



Thanks for the feedback!


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

Re: Calculations

Postby regularexpress » Tue May 21, 2013 6:53 am

Sorry I didn't want to abuse, but now I'm stuck at this part:

Code: Select all
  var
SubPatterns: TStringsArray;
Begin
   SubPatterns:=SubMatchesRegEx(WideExtractBaseName(FileName),'(.*?)\[(\d+) by (\d+)\]',false);
   if Length(SubPatterns) <=0 then exit;
   FileName := FloatToStr(StrToFloat(SubPatterns[1]) / StrToFloat(SubPatterns[2]))
       + '  ~  ' + WideExtractBaseName(FileName) + WideExtractFileExt(FileName);
end.


I just changed IntToStr to FloatToStr and StrToInt to StrToFloat. The result is this:

FROM
Plane [696 by 52]

TO
13.384615384615 ~ Plane [696 by 52]

What can I do to limit the result to a certain number of decimal places? Sometimes I'll want 1 decimal point, or 2, etc. I tried to search for a while and study Pascal Script for a bit, but so far unsuccessful :(

The desirable result would be:
13.38 ~ Plane [696 by 52]

or even this if I can round more precisely:
13.39 ~ Plane [696 by 52]

Thank you very much anyway, if it wasn't for you it'd have taken a lot longer to even reach this step!
regularexpress
 
Posts: 4
Joined: Sun May 12, 2013 10:10 pm

Re: Calculations do the math

Postby Stefan » Tue May 21, 2013 10:37 am

.

Wrong forum , I guess :P ?

If you get more questions I suggest to register at that other forum.



I did a little research and found "FormatFloat()" at the den4b PascalScript wiki page


FROM:
Aircraft [696 by 52].txt
Aircraft [233 by 5].txt
Aircraft [245 by 8].txt

TO:
13,38 ~ Aircraft [696 by 52].txt
46,60 ~ Aircraft [233 by 5].txt
30,63 ~ Aircraft [245 by 8].txt

Instead of:
13 ~ Aircraft [696 by 52].txt
46 ~ Aircraft [233 by 5].txt
30 ~ Aircraft [245 by 8].txt


USE e.g.:

Code: Select all
var
  SubPatterns: TStringsArray;

Begin
   SubPatterns:=SubMatchesRegEx(WideExtractBaseName(FileName),'(.*?)\[(\d+) by (\d+)\]',false);
   if Length(SubPatterns) <=0 then exit;

   FileName := FormatFloat('##00.00',  StrToFloat(SubPatterns[1]) / StrToFloat(SubPatterns[2]))
            + '  ~  ' + WideExtractBaseName(FileName) + WideExtractFileExt(FileName);
end.




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

Re: Calculations

Postby regularexpress » Tue May 21, 2013 12:48 pm

Ah sorry, I'll admit I came here for your help, should've used the the new renamer's forum...

I actually got to a point where I would try to use FormatFloat (I also tried Format), but I couldn't write correctly. Man you can't believe how much I love you lol. Really thank you, I don't think I'll need anything else so soon and if do I'll use the other forum, or try to learn after all.

Really thank you for all the helps!
regularexpress
 
Posts: 4
Joined: Sun May 12, 2013 10:10 pm


Return to General Comments