检查Lua是否存在文件 [英] Check if a file exists with Lua

查看:73
本文介绍了检查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是否存在文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆