Hello,
I would like to make a script to load lyrics from a text file.
I know hot to get the right path and filename but I can't find a function to actually read the content of the file.
I've seen there is a function to do it from the clipboard but that isn't very usefull in my situation because i need to process a great number of files.
Does any of you know how to read from a text file?
Thanks
Read from a text file
Re: Read from a text file
This is a modification of the load_cover.sct, it will try to find a .txt file named after the original music file.
Code: Select all
Program LyricsFromFile;
var
i: integer;
sFile: string;
sl: TStringList;
begin
if not tg_init then exit;
i := 1;
sys_SetStatusText( 2, IntToStr( tg_GetRowCount ) );
sl := TStringList.Create;
try
repeat
tg_loadFile;
sys_SetStatusText( 1, IntToStr( i ) );
sys_SetStatusText( 3, gTag.Filename );
sFile := ChangeFileExt( gTag.Filename, '.txt' );
if FileExists( sFile ) then begin
sl.LoadFromFile( sFile );
gtag.Lyrics := sl.Text;
gTag.SaveToFile( 0, false, false );
tg_RefreshRow;
end;
i := i + 1;
until not tg_skip;
finally
sl.Free;
end;
end.
Re: Read from a text file
Thanks for the quick answer
There is a little mistake in the SaveToFile function (3rd argument is missing)
but it works perfectly well after correction.
Thanks again
There is a little mistake in the SaveToFile function (3rd argument is missing)
but it works perfectly well after correction.
Thanks again
-
- Sr. Member
- Posts: 294
- Joined: Wed Sep 15, 2010 1:38 pm
Re: Read from a text file
SaveToFile had 4 parameter in the older version, in 0.85 it has 3 - the original 3rd (string) parameter now omitted (it was '' when I used).luffy wrote:Thanks for the quick answer
There is a little mistake in the SaveToFile function (3rd argument is missing)
but it works perfectly well after correction.
Thanks again
Re: Read from a text file
I tried the function with your new beta, seems it works. so i will test it with a big amount of files to see if it also works.