#1 2013-05-06 06:48

TheDutchJewel
Member
Registered: 2013-05-06
Posts: 10

Modifications on a fixed position, case single char only

I often need to change upper or lower cases on a fixed position on a lot of files. For instance if I want to change only the fourth character of a file name from lower to upper case.

I tried a lot of file renamers, but only Métamorphose 2 was able to do this job. Check inside the program:  Renamer > Modifications > Fixed position.

Is it possible to add this option to ReNamer?

Offline

#2 2013-05-06 08:40

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: Modifications on a fixed position, case single char only

Hi and welcome!

Can you please remove your footer?
It is categorized as Proxy Avoidance, thank you!



I think currently we have to use an PascalScript for this case.

See our wiki for an how-to about PascalScript >>> http://www.den4b.com/wiki/ReNamer:Rules:PascalScript


You can add this code one or more times to your rules list.

Change   // USER SETTINGS to suit your needs, just modify the highlighted digits
  WantedChar := 4; //Work on char pos n
  WantedCase := 1; //1=Upper, 2=Lower


{Change case of one char to upper or lower case}
var
  WantedChar, WantedCase: Integer;
  Part1, Part2, Part3: WideString;
  
begin
  // USER SETTINGS:
  WantedChar := 4; //Work on char pos n
  WantedCase := 1; //1=Upper, 2=Lower

  //===================================
  // THE CODE:
  Part1 := WideCopy(FileName, 1, WantedChar-1);
  Part2 := WideCopy(FileName, WantedChar, 1);
  Part3 := WideCopy(FileName, WantedChar+1, 999);
  if (WantedCase = 1) Then Part2 := WideUpperCase(  Part2 );
  if (WantedCase = 2) Then Part2 := WideLowerCase(  Part2 );
  FileName := Part1 + Part2 + Part3;
end.

HTH?

# # # EDIT:



Updated script: change case of one OR more chars:

  WantedChar     := 6; //Start at char pos n
  WantedAmount := 3; //Work on this amount of next chars (tip: use 999 for "till the end")
  WantedCase     := 2; //1=Upper, 2=Lower

{Change case of one or more char(s) to upper or lower case}
var
  WantedChar, WantedCase, WantedAmount: Integer;
  Part1, Part2, Part3                 : WideString;
  
begin
  // USER SETTINGS:
  WantedChar   := 6; //Start at char pos n
  WantedAmount := 3; //Work on this amount of next chars (tip: use 999 for "till the end")
  WantedCase   := 2; //1=Upper, 2=Lower
  

  //===================================
  // THE CODE:
  Part1 := WideCopy(FileName, 1, WantedChar-1);
  Part2 := WideCopy(FileName, WantedChar, WantedAmount);
  Part3 := WideCopy(FileName, WantedChar+WantedAmount, 999);
  if (WantedCase = 1) Then Part2 := WideUpperCase(  Part2 );
  if (WantedCase = 2) Then Part2 := WideLowerCase(  Part2 );
  FileName := Part1 + Part2 + Part3;
end.

Another one

Change case of every char after first hyphen (or any other sign) till the end:

FROM:
Lou Bega - Mambo Nr 5.mp3
Maria Mena - Just a little bit.mp3
TO:
Lou Bega - MAMBO NR 5.MP3
Maria Mena - JUST A LITTLE BIT.MP3

{Change case of every char after first hyphen (or any other sign) till the end}
var
  Delimiter, Part1, Part2: WideString;
  Position, WantedCase        : Integer;
  
begin
   // USER SETTINGS:
   Delimiter  := '-'; //split filename at delimiter into Part1 and Part2
   WantedCase := 1;   //1=Upper, 2=Lower

  //===================================
  // THE CODE:
  Position := Pos(Delimiter, FileName);
  if (Position > 0) then
    begin
      Part1 := Copy(FileName, 1, Position-1);
      Part2 := Copy(FileName, Position, 999);
      
      if (WantedCase = 1) Then Part2 := WideUpperCase(Part2);
      if (WantedCase = 2) Then Part2 := WideLowerCase(Part2);
       
      FileName := Part1 + Part2;
    end;
end.



More?

Capitalize every word's 1rst letter:

//Capitalize every word's 1rst letter, leaving the rest unchanged
//laVern Baker ---> LaVern Baker
//o'Jays ---> O'Jays
//patti laBelle ---> Patti LaBelle
//http://www.den4b.com/forum/viewtopic.php?pid=3639#p3639
//krtek

var
  Words : TStringsArray;
  TempFileName : WideString;
  i : Integer;
begin
  TempFileName:='';
  Words:=WideSplitString(WideExtractBaseName(FileName), ' ');
  for i:=0 to Length(Words) - 1 do
  begin
    if(Length(Words[i])>0) then
      TempFileName := TempFileName + ' '+ WideUpperCase(Words[i][1]) +
        WideCopy(Words[i], 2, Length(Words[i])-1)
    else TempFileName:=TempFileName + ' ';
  end;
  FileName:=WideCopy(TempFileName, 2, Length(TempFileName)-1)+
    WideExtractFileExt(FileName);
end.


Even more complex issues can be handled:

// http://www.den4b.com/forum/viewtopic.php?id=176

//Script will capitalize the first letter 
//and put everything else in lower case for fragment of filename 
//which is between second dash and first opening square bracket (after the second dash). 
//If bracket not found, it will lower case for the rest of the filename after the second dash. 
//Make sure you use the latest version (v4.50 is required).

var
  I, PosStart, PosEnd: Integer;
  
begin
  PosStart := WidePos('-', FileName);
  if PosStart <= 0 then Exit;
  PosStart := WidePosEx('-', FileName, PosStart+1);
  if PosStart <= 0 then Exit;
  PosEnd := WidePosEx('[', FileName, PosStart+1);
  if PosEnd <= 0 then PosEnd := WideLength(FileName);
  
  FileName := WideCopy(FileName, 1, PosStart) +
    WideLowerCase(WideCopy(FileName, PosStart+1, PosEnd-PosStart-1)) +
    WideCopy(FileName, PosEnd, WideLength(FileName)-PosEnd+1);
  for I:=PosStart to PosEnd do
    if IsWideCharAlpha(FileName[i]) then
    begin
      FileName[i] := WideUpperCase(FileName[i])[1];
      Break;
    end;
end.

.

Last edited by Stefan (2013-10-01 07:26)


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

#3 2013-05-06 09:16

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: Modifications on a fixed position, case single char only

An enhanced CASE rule would be a dream and help e.g. many on renaming MP3 files too:

Change case on one char only:

[X] Work on range
From
(o)Position:  [ 4]
( )Delimiter: [  ]
Until
(o)Count:     [ 1]
( )Delimiter: [  ]
( )The End

Change case from hyphen till the end:

[X] Work on range
From
( )Position:  [  ]
(o)Delimiter: [ -]
Until
( )Count:     [  ]
( )Delimiter: [  ]
(o)The End

Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

#4 2013-05-06 16:25

TheDutchJewel
Member
Registered: 2013-05-06
Posts: 10

Re: Modifications on a fixed position, case single char only

Thanks for the quick response.

Script works fine, but an enhanced rule would make it even more convenient.

PS: Footer removed, even though I don't see the problem of proxy avoidance.

Offline

#5 2013-05-09 14:22

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,376

Re: Modifications on a fixed position, case single char only

Stefan wrote:

An enhanced CASE rule would be a dream and help

I really like this idea and Stefan's draft outline of the options. The question is where to place it? The "Case" rule is packed as it is.

I'll try to experiment with it and see what can be done.

Offline

Board footer

Powered by FluxBB