lua 文件是否存在

在 Lua 中,可以使用 lua 函数 io.open() 来检查文件是否存在。如果文件存在,io.open() 将返回文件句柄;如果文件不存在,它将返回 nil。

代码示例:

local file = io.open("filename.lua", "r")
if file then
   -- file exists
   io.close(file)
   -- file does not exist
        beyond__devil