require"lfs"
function findindir (path, wefind, r_table, intofolder)
for file in lfs.dir(path) do
if file ~= "." and file ~= ".." then
local f = path..'\\'..file
--print ("/t "..f)
if string.find(f, wefind) ~= nil then
--print("/t "..f)
table.insert(r_table, f)
end
local attr = lfs.attributes (f)
assert (type(attr) == "table")
if attr.mode == "directory" and intofolder then
findindir (f, wefind, r_table, intofolder)
else
--for name, value in pairs(attr) do
-- print (name, value)
--end
end
end
end
end
local currentFolder = [[C:\]]
-------------------------------------
local input_table = {}
findindir(currentFolder, "%.txt", input_table, false)--查找txt文件
i=1
while input_table[i]~=nil do
print(input_table[i])
i=i+1
end
lua遍历文件夹
最新推荐文章于 2024-09-11 06:50:56 发布