Page 1 of 1
Help with simple enhancement to the replace script
Posted: 2010-05-25 23:38:51
by scottdw
Here is the replace script that I use and it works:
Code: Select all
program FindReplace;
const
WholeWord = False;
Search = '\\tower\\Movies\\';
Replace = 'c:\Movies\';
Field = fieldURL;
var
s: string;
begin
s := GetField(Field);
if WholeWord then
begin
if s = Search then
SetField(Field, Replace);
end
else
SetField(Field, StringReplace(s, Search, Replace));
end.
I am going to be putting my movies each in their own folder named after the movie file:
Before: c:\Movies\Die Hard.mkv
After: c:\Movies\Die Hard\Die Hard.mkv
I want to name the folder after the Original Title field and though I could use this:
Code: Select all
program FindReplace;
const
WholeWord = False;
Search = '\\tower\\Movies\\';
[b] Replace = 'c:\Movies\' + MovieName + '\";[/b]
Field = fieldURL;
var
s: string;
begin
s := GetField(Field);
if WholeWord then
begin
if s = Search then
SetField(Field, Replace);
end
else
SetField(Field, StringReplace(s, Search, Replace));
end.
but I need help getting the info for MovieName from the "Original Title" field.
I tried what I could understand from looking at other scripts but could not get it.
Thanks,
Scott
Posted: 2010-05-26 19:30:12
by FinderX
use GetField(fieldOriginalTitle) and store in a variable, for example
MovieName := GetField(fieldOriginalTitle);
If you have problem with MovieName, perhaps is for the declaration of Replace in CONST.
Or the problem is another?
[/code]
Posted: 2010-05-26 20:47:46
by antp
As you do not want a static value as replace string, but something built from another info, it has to be done differently.
Remove "remplace" from the "const" group and put it in the "var" group (like "s") :
then just after the "s := GetField..." put:
Code: Select all
Replace := 'c:\Movies\' + GetField(fieldOriginaltTitle) + '\';
Posted: 2010-05-27 01:13:17
by scottdw
Thanks for the help but it is still not working for me but probably a mistake on my part.
I made the changes per antp to this:
Code: Select all
program FindReplace;
const
WholeWord = False;
Search = '\\tower\\Movies\\';
Field = fieldURL;
var
s: string;
Replace: string;
begin
s := GetField(Field);
Replace := 'c:\Movies\' + GetField(fieldOriginalTitle) + '\';
if WholeWord then
begin
if s = Search then
SetField(Field, Replace);
end
else
SetField(Field, StringReplace(s, Search, Replace));
end.
Did I mess up somewhere??
It did not make any changes...it just kept the path at the \\tower\movies.
Posted: 2010-05-27 09:20:33
by antp
you say that the path stays as \\tower\movies but you assigned to Search constant the value '\\tower\\Movies\\' ... that's normal that it does not find (and replace) it, since it is different

Assign the real value to Search then.
Or if you want to process all records, not just those with a particular value, you can just do this:
Code: Select all
program NewScript;
var
s: string;
begin
s := 'c:\Movies\' + GetField(fieldOriginalTitle) + '\';
SetField(fieldUrl, s);
end.
this will set the URL field of all selected movies
Posted: 2010-05-27 13:06:04
by scottdw
Doh....thanks that worked!!!!
Posted: 2010-05-27 14:21:46
by scottdw
Not to be pain here but I have another request that may be easy. Ultimately I want to change the URL field to \\tower\Movies\MovieTitle\MovieTitle.extention
Example: \\tower\Movies\rush hour.mkv
to
\\tower\Movies\rush hour\rush hour.mkv
the problem I am having is the extention...they all don't have the same extention. Is there a way to look at what is currently inthe URL field to get the extention then apply the above code and have the correct extention?
Thanks,
Scott
Posted: 2010-05-27 19:40:46
by antp
Also keep current file name? Or just the extension?
Maybe it is easier to do the replacement as originally planned then...
Code: Select all
program NewScript;
var
s: string;
begin
s := StringReplace(GetField(fieldUrl), 'c:\Movies\', 'c:\Movies\' + GetField(fieldOriginalTitle) + '\');
SetField(fieldUrl, s);
end.
It will replace c:\Movies\ by that + the title, keeping the current file name and extension at the end
But if you run it more than once on the same list, it will each time add a folder level.
Posted: 2010-05-27 19:51:23
by scottdw
That's perfect...THANKS!!!!!
I just wanted to keep the extension....but this works just fine.
Thanks again!!!!
Posted: 2010-05-28 12:20:35
by scottdw
Ok I am asking ALOT so if you just want to ignore this post...feel free
Some of my "OriginalTitle" fields don't have the name I want my folder to be.
Is it possible to pull out just the filename in the URL field, save it as a var...call it VAR1 for example. Then take VAR1 and strip the extension off and call it VAR2 and rename the URL field to: c:\Movies\VAR2\VAR1
Example:
Current URL: c:\Movies\Rush Hour.mkv
Make VAR1=Rush Hour.mkv
Make VAR2=Rush Hour
Which would make the URL field: c:\Movies\Rush Hour\Rush Hour.mkv
REALLY sorry to be a pain and your help is GREATLY appreciated!!!!!
Posted: 2010-05-29 15:47:58
by antp
Using LastPos function of StringUtils1 unit you can find the position of last \ then copy the remaining text in a variable.
Same for copying part of name before the dot.
Posted: 2010-06-01 17:32:56
by scottdw
Totally can't believe I figured it out!!!!!!
Thanks for the help.
Here is what I used:
Code: Select all
program Replacename;
uses
StringUtils1;
var
s: string;
Value: string;
Value2: string;
begin
Value := TextAfter(GetField(fieldUrl), '\\tower\\Movies\\');
Value2 := TextBefore(Value, '.', '');
s := StringReplace(GetField(fieldUrl), '\\tower\\Movies\\', '\\tower\Movies\' + Value2 + '\');
SetField(fieldURL, s);
end.
Don't know if it's the right way or ideal but it works perfectly
Thanks for all the help!