This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
lunatik3904's profile picture

Reading From Diskette

Started by lunatik3904, 25 February 2012 - 05:12 PM
lunatik3904 #1
Posted 25 February 2012 - 06:12 PM
Hello guys!

I just installed ComputerCraft(with Turtles) and was messing around with it for the last hour.
Since I suck BIG time in programming, I never figured out how to read data from a file on the diskette

My computer is linked with the floppy drive, I can detect if there is a diskette or not, data or not, but I don't know how to actually read the text from the file on diskette.


Thanks for your help!!

(Sorry for my bad English, my native language is French!)
rockymc #2
Posted 25 February 2012 - 06:46 PM
f = fs.open('your/path/to/disk/program', r)
print(f:readLines())
lunatik3904 #3
Posted 25 February 2012 - 07:17 PM
when trying with your code, it states "waiting for <eof> at blablabla
Rion #4
Posted 25 February 2012 - 07:24 PM
This Error usually happens to me, if i've put too much "end" commands in my code.
lunatik3904 #5
Posted 25 February 2012 - 07:42 PM
now it states
: bad argument, string expected.
Liraal #6
Posted 25 February 2012 - 07:50 PM
try 'f = fs.open('your/path/to/disk/program', "r")'
lunatik3904 #7
Posted 25 February 2012 - 07:57 PM
bad argument, string expected >_>
lunatik3904 #8
Posted 25 February 2012 - 08:01 PM
try 'f = fs.open('your/path/to/disk/program', "r")'
I tried it alone, and it returned no error.
However, when trying to add
'print(f:readLines())'
states attempt to call nil
Liraal #9
Posted 25 February 2012 - 08:04 PM
so try this (it's my preferable approach:D)

file=io.open(filepathwhatever, "r")
print(file:read("*a"))
lunatik3904 #10
Posted 25 February 2012 - 08:16 PM
damn xD surely there's something wrong with me, because now it states :
attempt to perform arithmetic __div on table and nil

zOMG
lunatik3904 #11
Posted 25 February 2012 - 11:44 PM
finaly found how!!!

file=io.open("filepathwhatever","r")
print(file:read())

damn " "