PDA

View Full Version : using io.open and reading the first line to a string



quixote
February 26th, 2007, 02:00 PM
I'm having a bit of trouble reading the first line of a file into a string using the io.open functions. I was hoping that someone could just spoon-feed me an example script, because I'm getting nowhere using the help file.

All I'm trying to do is have girder check my USB memory stick when it is plugged in and then read the first line of a file and compare it to another string.

Thanks in advance!

Ron
February 26th, 2007, 02:45 PM
untested:




f = io.open('file', "r")

line =f:read("*line")

f:close()

print(line)


from PIL
http://www.lua.org/pil/21.2.1.html

quixote
February 26th, 2007, 02:48 PM
Thanks! I'll try that out and let you know how it goes. It's for a door access project I'm trying.

quixote
February 27th, 2007, 09:12 AM
The script works perfectly. I have a couple of other more advanced questions relating to this project, but I'll start another thread. Thanks again.

Ron
February 27th, 2007, 09:13 AM
Awesome. Glad it worked.