Page 1 of 1

Calculations

PostPosted: Sun May 12, 2013 11:48 pm
by regularexpress
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!

Re: Calculations

PostPosted: Mon May 13, 2013 7:29 pm
by Stefan
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.

Re: Calculations

PostPosted: Thu May 16, 2013 12:00 am
by regularexpress
THANK YOU VERY MUCH.

I LOVE YOU.

Re: Calculations

PostPosted: Thu May 16, 2013 11:10 am
by Stefan
I miss three exclamation marks at least after the second statement. :D



Thanks for the feedback!


.

Re: Calculations

PostPosted: Tue May 21, 2013 6:53 am
by regularexpress
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!

Re: Calculations do the math

PostPosted: Tue May 21, 2013 10:37 am
by Stefan
.

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.




.

Re: Calculations

PostPosted: Tue May 21, 2013 12:48 pm
by regularexpress
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!