#1 2010-01-18 20:48

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

First part with Title, second part uppercase, third as it is

Question
i would like to have the second part only in uppercase and the first part with Title. Is it possible?

FROM:
aaa1A_2ExPreSs23_c120x160.jpg
pBcd12gh_ReGion1_A24aac.jpg
TO:
Aaa1A_2EXPRESS23_c120x160.jpg
PBcd12gh_REGION1_A24aac.jpg


Answer
To do this, split file name into parts:
RegEx: '(.)(.+_)(.+_)(.+)'

Explanation:
'(.)'  ==> Find one sign => 'a'
'(.+_)' ==> find one or more signs till an underscore => 'aa1A_'
'(.+_)' ==> find one or more signs till an underscore => '2ExPreSs23_'
'(.+)' ==> find the rest => 'c120x160'

Then replace group 1 / Parts[0] with uppercase char,
replace group 2 / Parts[1] as it is
group 3 / Parts[2] all upper case
the rest / Parts[3] as it is.

Here is an PascalScript code for ReNamer:

var
  Parts: TStringsArray;
  
begin
  Parts := SubMatchesRegEx(WideExtractBaseName(FileName), '(.)(.+_)(.+_)(.+)', FALSE);
  If (Length(Parts) <=0) then exit;

  FileName := WideUpperCase(Parts[0]) + Parts[1] + WideUpperCase(Parts[2]) + 
            Parts[3]  + WideExtractFileExt(FileName);
end.

See the wiki how to handle PascalScripts ==> http://www.den4b.com/wiki/ReNamer:Rules:PascalScript

- - -

Alternative:
FROM:
aaa1A_2ExPreSs23_c120x160.jpg
pBcd12gh_ReGion1_A24aac.jpg
TO:
Aaa1a_2EXPRESS23_c120x160.jpg
Pbcd12gh_REGION1_A24aac.jpg

var
  Parts: TStringsArray;
  
begin
  Parts := SubMatchesRegEx(WideExtractBaseName(FileName), '(.+_)(.+_)(.+)', FALSE);
  If (Length(Parts) <=0) then exit;

  FileName := WideCaseCapitalize(Parts[0]) + WideUpperCase(Parts[1]) + Parts[2] + 
            WideExtractFileExt(FileName);
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

#2 2010-02-26 22:18

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

Re: First part with Title, second part uppercase, third as it is

Question
I want to change a folder name to Title Case
excepts letters or words inside "[" and "]"
that is to keep unchanged the letters inside square brackets.

FROM:
model 500 - starlight [echospace 313LE] or
monolake - cyan [CR04] (1996)
TO:
Model 500 - Starlight [echospace 313LE] or
Monolake - Cyan [CR04] (1996)


Here is an PascalScript code for ReNamer:

var
  Parts: TStringsArray;
  
begin
  Parts := SubMatchesRegEx(WideExtractBaseName(FileName), '(.+)(\[.+)', FALSE);
  If (Length(Parts) <=0) then exit;
  FileName := WideCaseCapitalize(Parts[0])  + Parts[1]  + WideExtractFileExt(FileName); 
end.

See the wiki how to handle PascalScripts ==> http://www.den4b.com/wiki/ReNamer:Rules:PascalScript


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 2010-04-15 21:44

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

Re: First part with Title, second part uppercase, third as it is

FROM:
Mcewan, Ian - Aan Chesil Beach.epub
Mcfadyen, Cody - Het Gezicht Van De Dood.epub
Meyer, Stephenie - Nieuwe Maan.epub

TO:
Mcewan, Ian - Aan chesil beach.epub
Mcfadyen, Cody - Het gezicht van de dood.epub
Meyer, Stephenie - Nieuwe maan.epub

That's it:
Change to "Sentence case" after the dash -

To do this,
split file name into parts:
RegEx:
'(.+) - (.)(.+)',

Explanation:
for "Mcewan, Ian - Aan Chesil Beach"
'(.+)' ==> find one or more signs till an blank => 'Mcewan, Ian', stored in SubPattern  Parts[0]
' - ' ==> followed by dash blank => ' - '
'(.)'  ==> Find one sign => 'A' , stored in SubPattern  Parts[1]
'(.+)' ==> find the rest => 'an Chesil Beach', stored in SubPattern  Parts[2]


Here is an PascalScript code for ReNamer:

var
  Parts: TStringsArray;
  
begin
// Capitalize Every Word    WideCaseCapitalize
// lowercase                WideLowerCase
// UPPERCASE                WideUpperCase
// iNVERT cASE              WideCaseInvert
// First letter capital     WideUpperCase(SubPattern[x])     "Sentence case"

    Parts := SubMatchesRegEx(WideExtractBaseName(FileName), '(.+) - (.)(.+)', FALSE);
    If (Length(Parts) <=0) then exit;

    FileName := WideCaseCapitalize(Parts[0]) + ' - ' + WideUpperCase(Parts[1])  
                 + WideLowerCase(Parts[2])  + WideExtractFileExt(FileName);
end.

See the wiki how to handle PascalScripts ==> http://www.den4b.com/wiki/ReNamer:Rules:PascalScript


If the names are already provided as shown above at "FROM:", then this simplified script will work too:

var
  Parts: TStringsArray;
  
begin
    Parts := SubMatchesRegEx(WideExtractBaseName(FileName), '(.+ - .)(.+)', FALSE);
    If (Length(Parts) <=0) then exit;

    FileName := Parts[0] + WideLowerCase(Parts[1])  + WideExtractFileExt(FileName);
end.

'(.+ - .)' will match "Mcewan, Ian - A" and store in Parts[0] and replace without any change
'(.+)' match "an chesil beach" and store in Parts[1] and replace all in lowercase


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 2014-08-12 18:57

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

Re: First part with Title, second part uppercase, third as it is

Thanks for the above script. This works correct for filenames like "Lastname, Surname - This Is A Title".

But how to change filenames like "Lastname, Surname - (2014) This Is A Title" in "Lastname, Surname - (2014) This is a title"?

Or even "Lastname, Surname - [This Is A Series Title - 01] (2014) This Is A Title" in "Lastname, Surname - [This is a series title - 01] (2014) This is a title"?

Last edited by TheDutchJewel (2014-08-12 19:05)

Offline

#5 2014-08-12 22:33

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

Re: First part with Title, second part uppercase, third as it is

I needed 12 rules to make it possible:
- Rule 1: Lower case everything from the second letter after the dash " - "
- Rule 2-4: Sentence case all text after every closed round bracket ")"
- Rule 5-7: Sentence case all text after every open round bracket "("
- Rule 8-12: Sentence case all text between square brackets "[]"

Rule 1: Lower case everything from the second letter after the dash " - "

Rule 1:
- Capitalize the first character after the " - "
- Lower case the rest

var
  Parts: TStringsArray;
  
begin
    Parts := SubMatchesRegEx(WideExtractBaseName(FileName), '(.+ - .)(.+)', FALSE);
    If (Length(Parts) <=0) then exit;

    FileName := Parts[0] + WideLowerCase(Parts[1]) + WideExtractFileExt(FileName);
end.

Rule 2-4: Sentence case all text after every closed round bracket ")"

Rule 2:
- Make a seperator from the ")" by adding a space before it

Replace all ")" with " )" (skip extension)

Rule 3:
- Capitalize the first character after the " ) "
- Lower case the rest

var
  Parts: TStringsArray;
  
begin  
    Parts := SubMatchesRegEx(WideExtractBaseName(FileName), '(.+ \) )(.)(.+)', FALSE);
    If (Length(Parts) <=0) then exit;

    FileName := Parts[0] + WideUpperCase(Parts[1]) + WideLowerCase(Parts[2]) + WideExtractFileExt(FileName);
end.

Rule 4:
- Change " )" back to ")"

Replace all " )" with ")" (skip extension)

Rule 5-7: Sentence case all text after every open round bracket "("

Rule 5:
- Make a seperator from the "(" by adding a space after it

Replace all "(" with "( " (skip extension)

Rule 6:
- Capitalize the first character after the " ( "
- Lower case the rest

var
  Parts: TStringsArray;
  
begin  
    Parts := SubMatchesRegEx(WideExtractBaseName(FileName), '(.+ \( )(.)(.+)', FALSE);
    If (Length(Parts) <=0) then exit;

    FileName := Parts[0] + WideUpperCase(Parts[1]) + WideLowerCase(Parts[2]) + WideExtractFileExt(FileName);
end.

Rule 7:
- Change "( " back to "("

Replace all "( " with "(" (skip extension)

Rule 8-12: Sentence case all text between square brackets "[]"

Rule 8:
- Make a seperator from the "[" by adding a space after it

Replace all "[" with "[ " (skip extension)

Rule 9:
- Make a seperator from the "]" by adding a space before it

Replace all "]" with " ]" (skip extension)

Rule 10:
- Capitalize the first character after the " [ "
- Lower case the rest till the next " ] "
- Capitalize the first character after the " ] "
- Lower case the rest

var
  Parts: TStringsArray;
  
begin   
    Parts := SubMatchesRegEx(WideExtractBaseName(FileName), '(.+ \[ )(.)(.+ \] )(.)(.+)', FALSE);
    If (Length(Parts) <=0) then exit;

    FileName := Parts[0] + WideUpperCase(Parts[1]) + WideLowerCase(Parts[2]) + WideUpperCase(Parts[3]) + WideLowerCase(Parts[4]) + WideExtractFileExt(FileName);
end.

Rule 11:
- Change "[ " back to "["

Replace all "[ " with "[" (skip extension)

Rule 12:
- Change " ]" back to "]"

Replace all " ]" with "]" (skip extension)

Last edited by TheDutchJewel (2014-08-13 19:03)

Offline

#6 2014-08-13 12:14

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

Re: First part with Title, second part uppercase, third as it is

Sentence case, but part of file name only

Another vote for "WideCaseSentence()" big_smile big_smile

The description in the wiki (http://www.den4b.com/wiki/ReNamer:Pasca … g_Handling)
reads as "WideCaseCapitalize()" will work as sentence case on a whole string, but works word-wise "only".


I think I have already suggested WideCaseSentence
for working like WideCaseCapitalize but on whole sentences instead,
and I want to do it now again cool

Origin:
this is a series title - this is a title.ext

WideCaseCapitalize (on whole string):
This Is A Series Title - This Is A Title.ext

WideCaseSentence (applied on two parts of that string):
This is a series title - This is a title.ext



- - -


Fine you worked it out yourself, good work. wink

I would do it this way with one rule, by using an IF condition for names with different parts, and adjusted regular expressions:

FROM:
Lastname, Surname - This Is A Title.ext
Öastnäme, Sürname - This Is Ä Üitle.ext
Lastname, Surname - (2014) This Is A Title.ext
Lastname, Surname - [This Is A Series Title - 01] (2014) This Is A Title.ext

TO:
Lastname, Surname - This is a title.ext
Öastnäme, Sürname - This is ä üitle.ext
Lastname, Surname - (2014) This is a title.ext
Lastname, Surname - [This is a series title - 01] (2014) This is a title.ext


USE this PascalScript:

var
  Parts: TStringsArray;
  BaseName, FirstPart, SecondPart: WideString;
  PosHyphen: Integer;
  
begin
	BaseName   := WideExtractBaseName(FileName);
	PosHyphen  := WidePos('-',BaseName);
	FirstPart  := WideCopy(BaseName, 1, PosHyphen);
	SecondPart := WideCopy(BaseName, PosHyphen + 1, 999);
	SecondPart := WideLowerCase(SecondPart);
	
	if( WidePos('-',SecondPart)=0) then
	begin
	  Parts := SubMatchesRegEx(SecondPart, '(.*?[a-z])(.+)', FALSE);
	  If (Length(Parts) <=0) then exit;
	  
	  FileName := FirstPart + WideUpperCase(Parts[0]) + Parts[1] 
	                        + WideExtractFileExt(FileName)
	end else
	begin
	  Parts := SubMatchesRegEx(SecondPart, '(.*?[a-z])(.+) - (.*?[a-z])(.+)', FALSE);
	  If (Length(Parts) <=0) then exit;
	  
	  FileName := FirstPart + WideUpperCase(Parts[0]) + Parts[1] + ' - ' 
	                        + WideUpperCase(Parts[2]) + Parts[3] 
	                        + WideExtractFileExt(FileName);
	end;
end.

For an how to use >> see http://www.den4b.com/wiki/ReNamer:Pascal_Script


Explanation:

Splitting in FirstPart and SecondPart helps in let us simplifying the regex.

Also changing the case to lower on the SecondPart at first, simplify the work.

if( WidePos('-',SecondPart)=0) then >>>> will check if there is another hyphen in the SecondPart and decide accordingly.

(.*?[a-z]) >>>> ".*?" will match none-greedy none-or-more of any sign, until one char in the range of a-z appears.
"(.+)" then will match the rest of the string.

Once we have matched the right parts, we utilize den4b ReNamers PascalScript methods to change the case.
And because of this methods work on chars only, the captured leading signs, if any, doesn't matter.



HTH? big_smile         I am sure there are other ways too...

Last edited by Stefan (2014-08-13 12:38)


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

#7 2014-08-13 13:04

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

Re: First part with Title, second part uppercase, third as it is

This PascalScript is magic and works fine for the given formats! Many thanks for this optimized solution. smile

I see that my 12-rules also handles correctly this one:
FROM:
Lastname, Surname - [This Is The Series Title - 01] (2014) This Is The Translated Title (This Is The Original Title).ext
TO:
Lastname, Surname - [This is the series title - 01] (2014) This is the translated title (This is the original title).ext

And also this one:
FROM:
Lastname, Surname - Bundel (2014) This Is The Translated Title (This Is The Original Title).ext
TO:
Lastname, Surname - Bundel (2014) This is the translated title (This is the original title).ext

The PascalScript doesn't handle correctly the "(This Is The Original Title)" part in first example and "This Is The Translated Title (This Is The Original Title)" part in the second one. But I'm sure you can optimize the script to fix it. (I tried to fix it myself, but I still don't understand the script...)

Last edited by TheDutchJewel (2014-08-13 13:16)

Offline

#8 2014-08-14 09:26

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

Re: First part with Title, second part uppercase, third as it is

 
Challenge accepted.


FROM:
Lastname, Surname - This Is A Title.ext
Lastname, Surname - This Is A Bundle (2014)
Öastnäme, Sürname - This Is Ä Üitle (2).ext
Lastname, Surname - (2014) This Is A Title.ext
Lastname, Surname - [This Is A Series Title - 01] (2014) This Is A Title.ext
Lastname, Surname - [This Is A Series Title - 01] (2013) This Is A Title [Extended Version] New Release (2014) Directors Cut (3).ext
Lastname, Surname - [This Is The Series Title - 01] (2014) This Is The Translated Title (This Is The Original Title).ext
Lastname, Surname - Bundle (2014) This Is The Translated Title (This Is The Original Title).ext

TO:
Lastname, Surname - This is a title.ext
Lastname, Surname - This is a bundle (2014)
Öastnäme, Sürname - This is ä üitle (2).ext
Lastname, Surname - (2014) This is a title.ext
Lastname, Surname - [This is a series title - 01] (2014) This is a title.ext
Lastname, Surname - [This is a series title - 01] (2013) This is a title [Extended version] New release (2014) Directors cut (3).ext
Lastname, Surname - [This is the series title - 01] (2014) This is the translated title (This is the original title).ext
Lastname, Surname - Bundle (2014) This is the translated title (This is the original title).ext

RULE:
Make every first char after first hyphen and then after each bracket upper case.

Work flow:
- split in FirstPart and SecondPart to work on the later only
- change the whole SecondPart to lower case
- match just the first char of SecondPart and change them to upper case
- search for and split the SecondPart on brackets, again make first char upper case
- a key part is the regex, which match always the first char, even behind other signs:
(.*?[a-z]) >>> ".*?" will match none-greedy none-or-more of any sign, until one char in the range of a-z appears.
"(.+)" then will match the rest of the string.


USE PascalScript:

var
  Parts: TStringsArray;
  BaseName, FirstPart, SecondPart, tmp1, tmp2: WideString;
  PosHyphen, i: Integer;
  
begin
  BaseName   := WideExtractBaseName(FileName);
  PosHyphen  := WidePos('-',BaseName);
  FirstPart  := WideCopy(BaseName, 1, PosHyphen +1);
  SecondPart := WideLowerCase(WideCopy(BaseName, PosHyphen +2, 999));

      //do it on first char of every name: // even without any parenthesis:
      Parts := SubMatchesRegEx(SecondPart, '(.*?[a-z])(.+)', FALSE);
      If (Length(Parts) <=0) then exit;
      SecondPart   := WideUpperCase(Parts[0]) + Parts[1];

      //now for name with (, ), [ or ] brackets behind each of them:
      for i:=1 to Length(SecondPart)-1 do
      begin
          if (SecondPart[i] = '(') or (SecondPart[i] = ')') 
          or (SecondPart[i] = '[') or (SecondPart[i] = ']')
          or (SecondPart[i] = '{') or (SecondPart[i] = '}') then 
          begin
              tmp1  := WideCopy(SecondPart,   1,   i);
              tmp2  := WideCopy(SecondPart, i+1, 999);
              Parts := SubMatchesRegEx(tmp2, '(.*?[a-z])(.+)', FALSE);
              If (Length(Parts) > 0) then 
                 SecondPart := tmp1 + WideUpperCase(Parts[0]) + Parts[1];
          end;
      end;

  FileName := FirstPart + SecondPart + WideExtractFileExt(FileName);
end.

For an how to use den4b ReNamers' PascalScript Rule >> see http://www.den4b.com/wiki/ReNamer:Pascal_Script



 

Last edited by Stefan (2014-08-15 19:02)


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

#9 2014-08-14 13:07

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

Re: First part with Title, second part uppercase, third as it is

This one is perfect! smile

Thanks for the magic script and the clear explanation.

Offline

#10 2014-08-14 20:20

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

Re: First part with Title, second part uppercase, third as it is

There's still one problem with the PascalScript:

FROM:
Lastname, Surname - This Is A Bundle (2014)

TO:
Lastname, Surname - This Is A Bundle (2014)

This should be:
Lastname, Surname - This is a bundle (2014)

Offline

Board footer

Powered by FluxBB