如何写代逐个读取文件夹中TXT文件的内容?
lua吧
全部回复
仅看楼主
level 3
通天沃特 楼主
??有人知道?
2015年12月02日 03点12分 1
level 3
通天沃特 楼主
2015年12月02日 03点12分 2
level 3
require "lfs"
local path = "C:\\Program Files"; --你要遍历的文件夹路径,注意要使用\\
function LoadFile(path)
for f in lfs.dir(path) do
if f ~= "." and f ~= ".." and f ~= ".svn" then --因为这里我的目录有装svn,所以忽略一下".svn"的情况
f = path .. "/"..f;
local attr = lfs.attributes(f);
if attr.mode == "directory" then
LoadFile(f);
elseif attr.mode == "file" then
f = string.gsub(f, "/", "\\"); --将"/"转换成"\"
local file = io.open(f, "r");
local cur = file:read("*a");
print(cur);
file:close();
end
end
end
end
LoadFile(path);
2015年12月02日 03点12分 3
安卓版可以写吗
2015年12月05日 14点12分
level 3
通天沃特 楼主
安卓版?
2015年12月05日 14点12分 4
1