Script to read file

I have used all the variables and funtions of jscripts to read a local txt file and show it on a tile (1 line)

what is the proper code ?

I use this:

function ReadFile()
 {
 var FileOpener = new ActiveXObject(“Scripting.FileSystemObject”);
 var FilePointer = FileOpener.OpenTextFile(“C:Zeeshan.txt”, 1, true);
 FileContents = FilePointer.ReadAll(); // we can use FilePointer.ReadAll() to read all the lines
 alert(FileContents);
 FilePointer.Close();
 }

You don’t need the FileSystemObject, emre has added a helper for text file reading.
One sec will find…

var listFile = file.ReadFromFile("C:\\Pinglog.txt");

To read specific lines youll need additional bits but if only one line just that with the file location should work.

is not a valid file path…
You need to use either double \ or something else which I cant remember right now.

C:\\Zeeshan.txt

If its in root of C drive.

1 Like

mistyping :smile: ,

return listfile variable from function so function returns a value other than undefined.

Also don’t forget the () on the testfield

Sorry for asking , is the code right ;

No, add a line of

return listfile

at the end and test with

readnow()

Also every / should be double \ not just the c;

1 Like

i would appreciate a little help please :smiley:

Two answers have been given that explain what you need. You must have the function RETURN something. This is usually the last line of the script.

function nowplaying(filepath) {
  var artist = file.ReadFromFile(filepath+'\\Snip_Artist.txt');
  var song = file.ReadFromFile(filepath+'\\Snip_Track.txt');
  if (song=='') {
    return '<size 14>Click here to start Music</size>';
  }
  return '<italic>' + song + '</italic><linebreak/>' + artist;
}
1 Like

Thank you @QMcKay you rule …

Happy New Year with happiness …

1 Like

And someone knows where to find these bits?