Difference between revisions of "ReNamer:Scripts:Partial case change"

From den4b Wiki
Jump to navigation Jump to search
(Bumped up version requirements)
m (Text replacement - "<source>" to "<syntaxhighlight lang="pascal">")
Line 24: Line 24:
 
|}
 
|}
  
<source>
+
<syntaxhighlight lang="pascal">
 
var
 
var
 
   I: Integer;
 
   I: Integer;
Line 55: Line 55:
 
|}
 
|}
  
<source>
+
<syntaxhighlight lang="pascal">
 
const
 
const
 
   DELIMITER = ' - ';
 
   DELIMITER = ' - ';

Revision as of 16:00, 8 February 2017

Users often want to change the case of the filename and not necessarily the case of the whole name like in the Case rule. Below are several scripts which demonstrate how to change the case of specific parts of the filename. They can be easily adjusted to suit other patterns.

Tested

  • ReNamer 5.74.4 Beta

Code A

Author: Denis Kozlov. Date: 9 February 2011.

Convert to upper case everything before the first " - " (spaced dash). Beware, the filename will remain unchanged if dash is not found.

Input Name Output Name
artist name - song title ARTIST NAME - song title
no dash in the name no dash in the name

<syntaxhighlight lang="pascal"> var

 I: Integer;

begin

 I := WidePos(' - ', FileName);
 if I > 0 then
   FileName := WideUpperCase(WideCopy(FileName, 1, I - 1)) +
     WideCopy(FileName, I, WideLength(FileName) - I + 1);

end. </source>

Code B

Author: Denis Kozlov. Date: 9 February 2011.

Capitalize every word in the first part of the name separated by " - " (spaced dash) and capitalize every first letter of the remaining parts like in sentences. No limitation on number of parts. If not dashes found, the whole name is treated as a frist and only part. Leave extension unchanged.

Input Name Output Name
artist name - song title Artist Name - Song title
artist name - album name - song title Artist Name - Album name - Song title
no dash in the name No Dash In The Name

<syntaxhighlight lang="pascal"> const

 DELIMITER = ' - ';

var

 NewName: WideString;
 Parts: TWideStringArray;
 I: Integer;
 

function SentenseCapitalize(const S: WideString): WideString; begin

 if WideLength(S) > 0 then
   Result := WideUpperCase(WideCopy(S, 1, 1)) +
     WideLowerCase(WideCopy(S, 2, WideLength(S) - 1))
 else
   Result := ;

end;

begin

 Parts := WideSplitString(WideExtractBaseName(FileName), DELIMITER);
 if Length(Parts) > 0 then
 begin
   NewName := WideCaseCapitalize(Parts[0]);
   if Length(Parts) > 1 then
     for I := 1 to Length(Parts) - 1 do
       NewName := NewName + DELIMITER + SentenseCapitalize(Parts[I]);
   FileName := NewName + WideExtractFileExt(FileName);
 end;

end. </source>