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

From den4b Wiki
Jump to navigation Jump to search
(Replaced the use of TStringsArray with TWideStringArray.)
m (Text replacement - "</source>" to "</syntaxhighlight>")
 
(2 intermediate revisions by the same user not shown)
Line 5: Line 5:
 
== Tested ==
 
== Tested ==
  
* ReNamer 5.50+ Beta
+
* ReNamer 5.74.4 Beta
  
 
== Code A ==
 
== Code A ==
Line 24: Line 24:
 
|}
 
|}
  
<source>
+
<syntaxhighlight lang="pascal">
 
var
 
var
 
   I: Integer;
 
   I: Integer;
Line 33: Line 33:
 
       WideCopy(FileName, I, WideLength(FileName) - I + 1);
 
       WideCopy(FileName, I, WideLength(FileName) - I + 1);
 
end.
 
end.
</source>
+
</syntaxhighlight>
  
 
== Code B ==
 
== Code B ==
Line 55: Line 55:
 
|}
 
|}
  
<source>
+
<syntaxhighlight lang="pascal">
 
const
 
const
 
   DELIMITER = ' - ';
 
   DELIMITER = ' - ';
Line 84: Line 84:
 
   end;
 
   end;
 
end.
 
end.
</source>
+
</syntaxhighlight>

Latest revision as of 15: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
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.

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
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.