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

[Lua] Can you program this for me?

Started by mibac138, 25 November 2012 - 05:58 AM
mibac138 #1
Posted 25 November 2012 - 06:58 AM
if example-file exist then

thanks :D/>/>
Kingdaro #2
Posted 25 November 2012 - 07:16 AM

local file = fs.open('somefile','r')
if file then
  local filecontents = file.readAll()
  file.close()
end
Something like this?

Or if you just wanted to see if a file exists:

if fs.exists('somefile') then
  -- stuff
end
mibac138 #3
Posted 25 November 2012 - 07:28 AM
code number 2 but what doing code number 1 ?
Kingdaro #4
Posted 25 November 2012 - 07:30 AM
The first one is reading files.
mibac138 #5
Posted 25 November 2012 - 07:30 AM
thanks :D/>/>
mibac138 #6
Posted 25 November 2012 - 07:43 AM
oh, i forgot how to do if example-file dont exist then
example-file create
Kingdaro #7
Posted 25 November 2012 - 08:00 AM
You can't create a file directly, but you can use fs.open('somefile','w')


local filename = 'somefile'
if not fs.exists(filename) then
  fs.open(filename, 'w')
  fs.close(filename)
end
mibac138 #8
Posted 25 November 2012 - 08:03 AM
thanks again :D/>/>