#1 2020-06-22 19:29

Torsten01
Member
Registered: 2020-06-22
Posts: 7

Use ReNamer only for a part of the filename

Dear experts, I have a question.
I have filenames like
"Left PART-Right PART of THE first fileNAME 001"
I want to leave the left part (before the hyphen) unchanged.
Is there a possibility to set the rules in ReNamer that it only changes the right part, after the hyphen?
I want to remove the spaces and "captitalize and preserve" the right part of the filenames (after the hyphen).
=>
"Left PART-RightPARTOfTHEFirstFileNAME001"

Best regards
Torsten

Last edited by Torsten01 (2020-06-22 19:48)

Offline

#2 2020-06-22 22:32

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

Re: Use ReNamer only for a part of the filename

Currently, there is no easy way to apply rules only to a part of the filename.

However, your task can be accomplished with the Pascal Script rule, using a script below:

var
  HyphenPos: Integer;
  BaseName, PartLeft, PartRight: WideString;
begin
  HyphenPos := WidePos('-', FileName);
  if HyphenPos > 0 then
  begin
    BaseName := WideStripExtension(FileName);
    PartLeft := WideCopy(BaseName, 1, HyphenPos);
    PartRight := WideCopy(BaseName, HyphenPos+1, WideLength(BaseName));
    PartRight := ReplaceRegEx(PartRight, '\b(\w)', '\u$1', False, True);
    PartRight := WideReplaceStr(PartRight, ' ', '');
    FileName := PartLeft + PartRight + WideExtractFileExt(FileName);
  end;
end.

Offline

#3 2020-06-23 19:06

Torsten01
Member
Registered: 2020-06-22
Posts: 7

Re: Use ReNamer only for a part of the filename

Thank you very much for the Pascal Script. It's exactly doing what I want smile

Offline

#4 2020-06-23 22:46

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

Re: Use ReNamer only for a part of the filename

By the way, you can learn more about the scripting features at our Pascal Script wiki article.

Offline

#5 2020-06-24 18:56

Torsten01
Member
Registered: 2020-06-22
Posts: 7

Re: Use ReNamer only for a part of the filename

Thank you for this hint. I am not really able to write scripts in Pascal but I understand the script you have created except the following line: "PartRight := ReplaceRegEx(PartRight, '\b(\w)', '\u$1', False, True);"
Could you explain to me what "'\b(\w)', '\u$1', False, True" is doing?

Last edited by Torsten01 (2020-06-24 19:11)

Offline

#6 2020-06-24 19:29

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

Re: Use ReNamer only for a part of the filename

ReplaceRegEx() >>> https://www.den4b.com/wiki/ReNamer:Pasc … xpressions

ReplaceRegEx(Input, Find     , Replace, CaseSensitive, UseSubstitution);
ReplaceRegEx(Input, '\b(\w)', '\u$1'   , CaseSensitive, UseSubstitution);


\b + \w + \u >>> https://www.den4b.com/wiki/ReNamer:Regular_Expressions
For "(...) and $1" >>> see there at "Substitution of text using backreference"
Means: find one sign of "an alphanumeric character" at a "word boundary" and capture the match in (...) parentheses
for reuse later by $1, which has the option \u to "Convert all characters to upper case".
So match the first sign of an word and change the case to upper, if need or not.




 


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 2020-06-24 19:38

Torsten01
Member
Registered: 2020-06-22
Posts: 7

Re: Use ReNamer only for a part of the filename

Thank you very much!

Offline

Board footer

Powered by FluxBB