本文介绍了使用 Lua 检查文件是否存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用 Lua 检查文件是否存在?
How can I check if a file exists using Lua?
推荐答案
尝试
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.
这篇关于使用 Lua 检查文件是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!