暂时写一种,留待补充,关键点是lfs 这个东西
require "lfs"
local oldpath = lfs.currentdir()
lfs.chdir("src//app//core//")
echo("is file exit??")
if io.exists("c15.lua") then
echo("yes!!!")
else
echo("no!!")
end
lfs.chdir(oldpath)
另一种类似的方法
local lfs = require "lfs"
local path = lfs.currentdir()
local fileName = package.searchpath("c"..id,path.."/src/app/core/?.lua")
if fileName~=nil then
print("fffffffffff:"..fileName)
card = require("app.core.c"..id).new(id)
else
card = require("app.core.Card").new(id)
end
本文详细介绍了Lua中使用lfs模块进行目录切换及文件存在性检查,并通过package.searchpath函数查找特定路径下的文件,展示了Lua语言在文件系统操作方面的强大能力。
6543

被折叠的 条评论
为什么被折叠?



