如何检查 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
关于lua - 检查目录是否存在于lua中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1340230/