如何检查 lua 中是否存在目录,如果可能的话最好不使用 LuaFileSystem 模块?
尝试做类似以下 python 行的事情:
os.path.isdir(path)
这是一种在 Unix 和 Windows 上都适用的方式,无需任何外部依赖:
--- Check if a file or directory exists in this path
function exists(file)
local ok, err, code = os.rename(file, file)
if not ok then
if code == 13 then
-- Permission denied, but it exists
return true
end
end
return ok, err
end
--- Check if a directory exists in this path
function isdir(path)
-- "/" works on both Unix and Windows
return exists(path.."/")
end
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)