您的位置:首页 > 编程语言 > Lua

遍历指定文件夹中特定某个格式的文件 (lua编写)

2014-10-16 10:02 417 查看
require"lfs"

--遍历某个文件夹中特定格式的文件,并插入到表格中

function findtemp(path,wefind,filetable)
for file in lfs.dir(path) do
if string.find(file,wefind) then
table.insert(filetable,file)
end
end

end

--搜索某盘中特定的文件夹

function findindir(path,wefind,filetable)
for file in lfs.dir(path) do
local f=path..'\\'..file
if string.find(f,wefind) then
findtemp(f,"%.csv",filetable)
return
end
end

end

local crrentFolder=[[F:]]

------------------------------

local filetable={}

findindir(crrentFolder,"temp",filetable)
i=1

--输出某个特定文件夹中某个格式的所有文件名

while filetable[i]~=nil do
print(filetable[i])
i=i+1

end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息