You are not logged in.
Pages: 1
Hello,
I am not an expert in this program yet, neither in Pascal. However ReNamer is a very practical tool in a wide application area!
Now with music I have a problem: can anybody tell me how to convert these filename examples
e.g. from:
The Corrs - All In a Day
David Bowie - Beauty and The Beast.mp3
to:
The Corrs - All in a day
David Bowie - Beauty and the beast.mp3
so keeping the artist and replacing the title to lower case (but the first character upper case).
Offline
Use my script from here
with regex like this:
REGEX = '^[^-]+-\s?(.+)$';
and
CHANGE_CASE = 3;
and empty to_skip string:
TO_SKIP = '';
Last edited by krtek (2009-03-04 20:20)
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
Hi krtek,
This certainly needs some more study on my side to implement. But your messages are very clear and explanatory, so I hope I can manage this weekend. Thank you very much indeed!
Offline
Let's make the script explicit, then. That's the script you need:
//SCRIPT CONTROLS:
//Legend:
//1. Uppercase
//2. Lowercase
//3. First letter capital
CHANGE_CASE = 3;
REGEX = '^[^-]+-\s?(.+)$';
TO_SKIP = ''; //Here you can put words that you want to be skipped by script.
//The case convertion won't be applied to them.
//Seperate them with DELIMITER
//And remember that you need to make them explicit. Remove any escape signs.
//They need to be strings already matched by regex, so Feat. instead of Feat\.
DELIMITER = '|'; //Delimiter of words in TO_SKIP string
CASE_SENSITIVE = False; //Should searching with regex be case sensitive? Default: False
//END OF SCRIPT CONTROLS
var
Matches, SubPatterns : TStringsArray;
TempFilename, FileNameNoEXT : WideString;
start_pos, end_pos, i, j : Integer;
Initialized, TimeToExit, NeedSkipping, NotAFullMatch : Boolean;
Skip : TStringsArray;
Answer : WideString;
procedure Initialize;
begin
Skip:=WideSplitString(TO_SKIP, DELIMITER);
Answer:='Type just word BREAK in here to exit the script';
end;
begin
if not TimeToExit then
begin
if not Initialized then Initialize;
TempFilename:='';
end_pos:=0;
start_pos:=1;
SetLength(SubPatterns,0);
SetLength(Matches,0);
NotAFullMatch:=false;
FileNameNoEXT:=WideStripExtension(FileName);
Matches:=MatchesRegEx(FileNameNoEXT, REGEX, CASE_SENSITIVE);
if Length(Matches) <= 0 then exit;
if Matches[0] <> FileNameNoEXT then NotAFullMatch:=true;
SubPatterns:=SubMatchesRegEx(Matches[0],REGEX,CASE_SENSITIVE);
if Length(SubPatterns) <=0 then exit;
for i:=0 to Length(SubPatterns)-1 do
if SubPatterns[i]<>'' then
begin
NeedSkipping:=false;
end_pos:=WidePos(SubPatterns[i], Matches[0])-1;
TempFileName:=TempFileName+WideCopy(Matches[0], start_pos, end_pos-start_pos+1);
start_pos:=end_pos+Length(SubPatterns[i])+1;
for j:=0 to Length(Skip)-1 do
if WideSameText(SubPatterns[i],Skip[j]) then NeedSkipping:=true;
if not NeedSkipping then
case CHANGE_CASE of
1 : TempFilename:=TempFileName+WideUpperCase(SubPatterns[i]);
2 : TempFilename:=TempFileName+WideLowerCase(SubPatterns[i]);
3 : TempFilename:=TempFileName+WideUpperCase(SubPatterns[i][1])+WideLowerCase(WideCopy(SubPatterns[i], 2, Length(SubPatterns[i])-1));
else
begin
ShowMessage('The value of CHANGE_CASE constant is invalid. Check legend for info.');
TimeToExit:=True;
break;
end;
end
else
TempFilename:=TempFileName+SubPatterns[i];
end;
if start_pos < Length(FileNameNoEXT) then
TempFilename:=TempFileName+WideCopy(FileNameNoEXT, start_pos, Length(FileNameNoEXT)-start_pos+1);
if NotAFullMatch then
if not WideInputQuery('RegEx didn''t match the full filename.', 'Old filename:'+#10+FileName+#10+#10+'Proposed new filename: '+#10+TempFileName+WideExtractFileExt(FileName)+#10+#10+'What should we do?'#10+#10+'Pressing OK button = Rename that file'+#10+'Pressing Cancek button = Skip that file'+#10+'Type ''break'' in the text field to exit the script'+#10, Answer) then
exit
else if WideSameText(WideLowerCase(Answer),'break') then
begin
TimeToExit:=True;
exit;
end
else
Answer:='Type just word BREAK in here to exit the script';
FileName:=TempFileName+WideExtractFileExt(FileName);
end
else exit;
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
Thank you again Krtek. In meantime I made the changes in the script and run it. Initially it was not clear to me what to do with the script, but I found out:
Add - PascalScript
copy the script to Configuration window
Try to Compile
Add Rule
It was just as easy as that (luckily I have some experience with Pascal (very long time ago) and PHP. Most programming languages are quite similar, and you commented it very well!!
ReNamer is a very good and flexible program. I learned a lot, and fast.
Many thanks again!
Offline
Pages: 1