Skip to main content
Jetawn
Participant
January 13, 2016
Answered

How to load text file into an array and retrieve data line by line?

  • January 13, 2016
  • 1 reply
  • 412 views

I am looking for help understanding how to open a text file, load each line to an array.  The data will be recalled to change content of text layer.  Thank you for any help.

This topic has been closed for replies.
Correct answer Tom Ruark

// i didn't test this code but something like

var a = [];

var f = new File(Folder.desktop + "/TestFile.txt");

if (f.open('r')) {

while ( ! f.eof) {

a.push(f.readln());

}

f.close();

}

alert("I read " + a.length + " lines from the file.");

for (var i = 0; i < a.length; i++) {

DoSomethingWithThisLine(a); // <-- you need to write this

}

1 reply

Tom Ruark
Tom RuarkCorrect answer
Inspiring
January 13, 2016

// i didn't test this code but something like

var a = [];

var f = new File(Folder.desktop + "/TestFile.txt");

if (f.open('r')) {

while ( ! f.eof) {

a.push(f.readln());

}

f.close();

}

alert("I read " + a.length + " lines from the file.");

for (var i = 0; i < a.length; i++) {

DoSomethingWithThisLine(a); // <-- you need to write this

}

Jetawn
JetawnAuthor
Participant
January 13, 2016

Thank you, sir!  Worked perfectly.  I appreciate the help.