Page 1 of 1

Read from a text file

Posted: Sun Nov 25, 2012 12:45 am
by luffy
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

Re: Read from a text file

Posted: Sun Nov 25, 2012 3:08 pm
by jtclipper
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

Posted: Mon Nov 26, 2012 7:37 am
by luffy
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

Posted: Mon Nov 26, 2012 9:16 am
by hopalongrock
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
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).

Re: Read from a text file

Posted: Thu Jan 30, 2014 9:08 am
by faris
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.