Difference between revisions of "File.readLines"

From MiniScript Wiki
Jump to navigation Jump to search
(Initial file.readLines page.)
 
(Change iteration over foods list directly instead of range of indexes)
 
Line 23: Line 23:
 
else
 
else
 
   print "My favorite foods are: "
 
   print "My favorite foods are: "
   for i in range(0, foods.len-1)
+
   for food in foods
     print "  " + foods[i]
+
     print "  " + food
 
   end for
 
   end for
 
end if
 
end if

Latest revision as of 18:58, 26 October 2022

In Mini Micro and command-line MiniScript, the file.readLines function reads a file into an array of strings.

file.readLines will return null on any file it cannot open or read.

Arguments

Parameter Name Meaning
filePath an absolute or relative path of the file to be read.

See also: file.writeLines

Example

fileName = "myfoods.txt"
foods = file.readLines(fileName)

if foods == null then
  print "[" + fileName + "] cannot be read."
else
  print "My favorite foods are: "
  for food in foods
    print "  " + food
  end for
end if