You are not logged in.
Hello Denis,
First, congratulations for this excelent program!
And now I have one question:
I want to rename a portion of a file with the rule Case: "First Letter Capital". I need rename starting in a position determined.
For example:
Growing Pains - 1x01 - This Is The First Episode [dvdrip]
I want to rename only the string "This Is The First Episode" with "This is the first episode":
Growing Pains - 1x01 - This is the first episode [dvdrip]
I tried with Pascal, but only know the Lowercase or Upercase functions...
Please, help me!:rolleyes:
Thanks for this good program.
Jesus.
Offline
Hey there!
It's possible with pascal script. I can write it for you, just tell me what exactly determines the position from which you want to set first letter capital. Is it always after second "-" (dash) symbol?
Offline
Hi Denis!
Yes, the second dash "-" is the first position for set "First letter capital", and the symbol "[" it's the end position, like the example.
Thanks for the quickly reponse.
Regards.;)
Offline
Here you go..
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.
Offline
Thanks Denis, the script work perfectly
You are the number one!
Jesus.
Offline
Hi Denis,
I've finally managed to write my first PascalScript. Well...not write to be accurate.. I've managed to modify existing script and made it to do what I want:-)
I needed it to Uppercase the part of filename after ']'.
And it does it:-)
But there is one thing I can't figure out in that code.
What [1] in the line:
FileName[i] := WideUpperCase(FileName[i])[1];
does?
It seems to do some type conversion... But what and how?
var
I, PosStart, PosEnd: Integer;
begin
PosStart := WidePos(']', FileName);
if PosStart <= 0 then Exit;
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.
Regular Expressions are not as hard to understand as you may think. Check ReNamer's manual or nice Regular Expressions tutorial for more info and start to use full power of applications that use them (like ReNamer, Mp3Tag and so on).
Offline
krtek, I'm glad that you are getting your skills onto scripts
First of all, there are two different types to represent text: String and WideString. First is for ANSI text (1 byte per character), and second is for UNICODE text (2 bytes per character). They both have same structure, where each character can be accessed by its index, i.e. [1], [2], ..., [N]. Note that in String and WideString first character has index 1, not like in arrays! Now, since there are 2 types for representing text, there must be 2 types for representing characters, so... String[i] -> Char, WideString[i] -> WideChar.
That was an introduction
Now, look at the syntax of the WideUpperCase function:
function WideUpperCase(const S: WideString): WideString;
Complier can automatically convert character into string type, but not other way around.
So you can do FileName[i] := FileName[i] and FileName := FileName[i], but cannot do FileName[i] := FileName;
Back to the original problem....
* FileName[i] - gives us a character,
* WideUpperCase(FileName[i]) - gives use an upper case character AS STRING,
* WideUpperCase(FileName[i])[1] - gives use the first upper case character of that string,
* FileName[i] := WideUpperCase(FileName[i])[1] - puts each character into upper case.
I hope it clears up few things
Offline
Thanks a lot, Denis!
It definitely cleared few things up for me
I had no idea that you can refer to index of string that is result of function without assigning that result to a variable. That really shortens notation.
Regular Expressions are not as hard to understand as you may think. Check ReNamer's manual or nice Regular Expressions tutorial for more info and start to use full power of applications that use them (like ReNamer, Mp3Tag and so on).
Offline
To make your life even easier, I've added two helper functions:
function WideCharUpper(const WC: WideChar): WideChar;
function WideCharLower(const WC: WideChar): WideChar;
So now you don't need to do that [1] casting, just use:
FileName[i] := WideCharUpper(FileName[i]);
Offline