17 posts
Location
The Internet
Posted 21 April 2015 - 04:25 PM
I am trying to create a program that reads every file in a directory and prints out everything. This is my Code so far:
http://pastebin.com//wPHnN0dQI get the error attempt to index ? (a nil value) in line 179 I just don't know why my line is defined so I don't know.
1426 posts
Location
Does anyone put something serious here?
Posted 21 April 2015 - 04:30 PM
If you look at line 179 you have:
line = file.readLine() -- This function reads the next line in the file, until the end.
Attempt to index nil means in this case that the file variable is nil. This is a result of opening a file that doesn't exist. Line 178 has
file = fs.open("Turtles"..turtleDataFiles[i],"r") -- Open a file for reading.
Turtles should be Turtles/ instead - you are opening a file called TurtlesWhatever instead of Turtles/Whatever.
Also instead of using a for i = 0, … loop you can do:
for _, name in pairs(fs.list("Turtles/")) do
Edited on 21 April 2015 - 02:31 PM
113 posts
Location
This page
Posted 21 April 2015 - 04:33 PM
Also remember that fs.list returns directories too. So you will need to add a check before you open the file to make sure it is not a directory.
17 posts
Location
The Internet
Posted 22 April 2015 - 01:13 PM
Ok thanks that worked but apparently I have a bug in my printing function called bigTable it starts at line 99. It should print out everything in every file each file should represent one line that doesn't work it just prints out everything in one line. This is my code:
http://pastebin.com/R5hY1ihk
17 posts
Location
The Internet
Posted 22 April 2015 - 04:40 PM
Ok sorry I found the mistake I forgot to reset the table and I had some other mistakes in there thanks for your help.