Lua检查一个文件是否存在 [英] Lua check if a file exists
本文介绍了Lua检查一个文件是否存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$ b $ b
function file_exists(name)
local f = io.open(name,r)
if f〜= nil then io.close f)返回true否则返回false结束
结束
但是请注意,该文件可以打开阅读。
How can i check if a file exists using 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.
这篇关于Lua检查一个文件是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文