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

Opening one file multiple times at the same time

Started by InputUsername, 04 January 2014 - 11:15 AM
InputUsername #1
Posted 04 January 2014 - 12:15 PM
Is it possible to open/use one file multiple times at the same time? (I'm sorry if this question has been asked before, couldn't find anything after a quick search.)

Example:
local r = fs.open("file","r")
local w = fs.open("file","w")

print(r.readAll())
w.write("this is text")

r.close()
w.close()

Thanks.
Edited on 04 January 2014 - 11:15 AM
CometWolf #2
Posted 04 January 2014 - 12:27 PM
I haven't actually tested this, hell why would you ever need to? But yeah it should be possible, however the read file will probably not change until you close both of them and open the read again.
wieselkatze #3
Posted 04 January 2014 - 12:28 PM
Why would you need that? (I don't think that would work, so no)

You could just write:

local f = fs.open("file", "r")
print(f.readAll())
f.close()
local f = fs.open("file", "w")
f.write("this is text")
f.close()
Edited on 04 January 2014 - 11:36 AM
InputUsername #4
Posted 04 January 2014 - 12:33 PM
I understand. Thanks for your help, I got it working with wieselkatze's solution.