Difference between revisions of "ReNamer:Scripts:Roman numerals serialization"

From den4b Wiki
Jump to navigation Jump to search
(Bumped up version requirements)
m (Text replacement - "</source>" to "</syntaxhighlight>")
Line 55: Line 55:
 
   FileName := WideExtractBaseName(FileName) + ' ' + ArabicToRoman(Count) + WideExtractFileExt(FileName);
 
   FileName := WideExtractBaseName(FileName) + ' ' + ArabicToRoman(Count) + WideExtractFileExt(FileName);
 
end.
 
end.
</source>
+
</syntaxhighlight>

Revision as of 15:01, 8 February 2017

The script does a serialization with roman numerals. The roman number is added at the end of the file name.

For example, "Book.doc" will turn into new "Book I.doc" and so on.

Tested

  • ReNamer 5.74.4 Beta

Code

Author: SafetyCar. Date: 09 January 2009.

<source> var

 Count: Integer;

function ArabicToRoman(Number:Integer): WideString; var

 Fulls, Halves: TWideStringArray;
 AllFulls, AllHalves, Arabic, Roman: WideString;
 I, U: Integer;
 

begin

 Roman  := ;
 Arabic := IntToStr(Number);
 
 AllFulls  := 'I|X|C|M|(X)|(C)|(M)';
 AllHalves := 'V|L|D|(V)|(L)|(D)';
   
 Fulls  := WideSplitString(AllFulls, '|');
 Halves := WideSplitString(AllHalves, '|');
 
 for I:=0 to Length(Arabic)-1 do
 begin
   U := StrToInt(Arabic[Length(Arabic)-I]);
   If U = 0 then Roman := Roman;
   If U = 1 then Roman := Fulls[i] + Roman;
   If U = 2 then Roman := Fulls[i] + Fulls[i] + Roman;
   If U = 3 then Roman := Fulls[i] + Fulls[i] + Fulls[i] + Roman;
   If U = 4 then Roman := Fulls[i] + Halves[i] + Roman;
   If U = 5 then Roman := Halves[i] + Roman;
   If U = 6 then Roman := Halves[i] + Fulls[i] + Roman;
   If U = 7 then Roman := Halves[i] + Fulls[i] + Fulls[i] + Roman;
   If U = 8 then Roman := Halves[i] + Fulls[i] + Fulls[i] + Fulls[i] + Roman;
   If U = 9 then Roman := Fulls[i] + Fulls[I+1] + Roman;
 end;
 
 Result := Roman;

end;

begin

 Count := Count + 1;
 FileName := WideExtractBaseName(FileName) + ' ' + ArabicToRoman(Count) + WideExtractFileExt(FileName);

end. </syntaxhighlight>