Read from a text file

Use this forum for everything concerning script usage
Post Reply
luffy
Newbie
Newbie
Posts: 2
Joined: Sun Nov 25, 2012 12:41 am

Read from a text file

Post 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

User avatar
jtclipper
Administrator
Administrator
Posts: 768
Joined: Tue Aug 10, 2010 12:04 pm

Re: Read from a text file

Post 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.

luffy
Newbie
Newbie
Posts: 2
Joined: Sun Nov 25, 2012 12:41 am

Re: Read from a text file

Post 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

hopalongrock
Sr. Member
Sr. Member
Posts: 289
Joined: Wed Sep 15, 2010 1:38 pm

Re: Read from a text file

Post 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).

faris
Newbie
Newbie
Posts: 1
Joined: Thu Jan 30, 2014 9:07 am

Re: Read from a text file

Post 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.

Post Reply