You are not logged in.
Pages: 1
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
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
Thank you very much for the Pascal Script. It's exactly doing what I want
Offline
By the way, you can learn more about the scripting features at our Pascal Script wiki article.
Offline
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
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
Thank you very much!
Offline
Pages: 1