Page 1 of 1

Rename Files

Posted: 2006-10-12 09:37:43
by Penanders
Do You think it's possible to rename the movie File with the value of the field transalated (or orignal) title by the scripts method?

It would be useful and really easy for the ant renamer programmer..

Posted: 2006-10-12 18:55:25
by antp
Using scripts it is possible actually.
As long as the title does not contain forbidden characters.

If you do something like that:

Code: Select all

program NewScript;
begin
  Launch('cmd /c ren "' + GetField(fieldUrl) + '" "' + GetField(fieldTranslatedTitle) + '.avi"');
end.
(not tested)
But this will open one console window per movie (it will be closed once renamed), so if you plan to do it on many movies it is maybe better to write the "ren" commands in a text field (using a TStringList) with a ".bat" extension, that you can launch manually later.

Posted: 2006-10-14 10:36:07
by Penanders
Uhmm

"launch" procedure seems to have problems with "cmd" command..
It work not at all.

Posted: 2006-10-14 11:19:59
by antp
Sorry, I forgot that parameter was separated:

Code: Select all

program NewScript;
begin
  Launch('cmd', '/c ren "' + GetField(fieldUrl) + '" "' + GetField(fieldTranslatedTitle) + '.avi"');
end.

Posted: 2006-10-17 10:29:52
by Penanders
Yes. It's as you suggest.

I've already solved so:

Code:
program Rename;
Var
Temp, Perc :String;
BegPos : integer;
begin
Launch('CMD','/C rename "'+GetField(FieldUrl)+'" "'+GetField(FieldTranslatedTitle)+'.avi"') ;
Perc := GetField(FieldUrl); // rinomina l'URL
Temp := '';
Repeat
BegPos := Pos('\', Perc);
Temp := Temp + (Copy(Perc,1,BegPos));
Delete(Perc,1,BegPos)
Until Begpos = 0;
Temp := Temp + (Getfield(FieldTranslatedTitle))+'.avi';
SetField(FieldUrl,temp);
end.


I would like a more practical script (i.e.: a bat file for several movies as you suggest) for the forbidden characters too.

I'm tryng to write it (It's easy i suppose).

Thanks for your help.

Ciao

Posted: 2006-10-17 15:00:26
by antp
For the batch file you can see how the "find duplicate" script reads/writes a TStringList.

To prevent forbidden characters, a for-loop on the string to check each character and replace it if needed should do the trick.
Something like that:

Code: Select all

for i := 1 to Length(s) do
begin
  if c := StrGet(s, i);
  if (c <> '?') and (c <> '*') etc... then
    s2 := s2 + c;
end;