Check if a file exists with Lua

Try

function file_exists(name)
   local f=io.open(name,"r")
   if f~=nil then io.close(f) return true else return false end
end

but note that this code only tests whether the file can be opened for reading.

Leave a Comment