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

fs.open(...,"w") How to delete?

Started by DeclipZ, 01 April 2015 - 02:01 PM
DeclipZ #1
Posted 01 April 2015 - 04:01 PM
Hi everyone!
When I experimented with FS API I've got a problem *again*. When I create file from function

fs.open(string,"w")
I can't delete it. How I can do it?
Sorry for my bad english
GopherAtl #2
Posted 01 April 2015 - 04:07 PM

fs.delete(filename).

But you have to close your file handles. fs.open() returns a file handle, which you have to catch to a variable, ex:


file=fs.open("derp","w")

then you have to close that handle when you're done writing to it


file.close()

otherwise the file is left open, and therefore can't be deleted, because it's open. In the latest versions, rebooting the computer that opened it seems to close it, allowing the file to be deleted, though I think there were issues with this in earlier versions of CC.
DeclipZ #3
Posted 01 April 2015 - 04:21 PM
Thank you! Rebooting helps me.