看了不少人的,主要还是错误处理有点问题,不多说了

贴代码:

require "lfs"

function getpathes(rootpath, pathes)
pathes = pathes or {} ret, files, iter = pcall(lfs.dir, rootpath)
if ret == false then
return pathes
end
for entry in files, iter do
local next = false
if entry ~= '.' and entry ~= '..' then
local path = rootpath .. '/' .. entry
local attr = lfs.attributes(path)
if attr == nil then
next = true
end if next == false then
if attr.mode == 'directory' then
getpathes(path, pathes)
else
table.insert(pathes, path)
end
end
end
next = false
end
return pathes
end pathes = {} getpathes("/", pathes) for key, path in pairs(pathes) do
print(key .. " " .. path)
end

lua遍历文件的更多相关文章

  1. lua遍历文件夹, zerobrane下载

    参考的这个http://www.cnblogs.com/jiufangding/p/3931585.html,配合批处理. zerobrane下载(上一篇博客忘掉了): http://files.cn ...

  2. C#遍历文件夹下所有文件

    FolderForm.cs的代码如下: using System; using System.Collections.Generic; using System.Diagnostics; using ...

  3. windowsAPI遍历文件夹(速度高于递归)

    #region API 遍历文件夹及其子文件夹和子文件 #region 声明WIN32API函数以及结构 ************************************** [DllImpo ...

  4. C# 遍历文件夹下所有子文件夹中的文件,得到文件名

    假设a文件夹在F盘下,代码如下.将文件名输出到一个ListBox中using System.Data;using System.Drawing;using System.Linq;using Syst ...

  5. python 遍历文件夹 文件

    python 遍历文件夹 文件   import os import os.path rootdir = "d:\data" # 指明被遍历的文件夹 for parent,dirn ...

  6. C#遍历文件夹及文件

    背景: 想自己实现一个网盘系统,于是需要用到遍历文件(夹)操作. C#基本知识梳理: 1.如何获取指定目录包含的文件和子目录 (1). DirectoryInfo.GetFiles():获取目录中(不 ...

  7. Java学习随笔3:遍历文件夹及文件的读取和写入

    import java.io.File; /** * 遍历文件夹 */ public class ScannerFile { public static void main(String[] args ...

  8. JAVA7遍历文件夹

    在JAVA7中提供了新的遍历文件的方法,比原有File类的递归遍历效率要好大约30%左右. 测试结果: 测试用的File类的递归,是经过对比测试几种方法,找出相对效率较好的来和JAVA7进行测试. 1 ...

  9. java 遍历文件夹里的文件

    Java遍历文件夹的2种方法: A.不使用递归: import java.io.File; import java.util.LinkedList; public class FileSystem { ...

随机推荐

  1. UGUI transform

    在编辑器中将UGUI对象挂在另一个物体上,UGUI预制体根对象位置调成零,调好位置后保存 由gameframework初始化,再挂到对应父对象上时,位置会有偏差,会更改锚点旋转等信息,需在OnWind ...

  2. Oracle job procedure 存储过程定时任务(转自hoojo)

    Oracle job procedure 存储过程定时任务 oracle job有定时执行的功能,可以在指定的时间点或每天的某个时间点自行执行任务. 一.查询系统中的job,可以查询视图 --相关视图 ...

  3. 【转】Cron表达式简介

    Cron表达式是一个字符串,字符串以5或6个空格隔开,分为6或7个域,每一个域代表一个含义,Cron有如下两种语法格式: Seconds Minutes Hours DayofMonth Month ...

  4. COGS 2259 异化多肽 —— 生成函数+多项式求逆

    题目:http://cogs.pro:8080/cogs/problem/problem.php?pid=2259 如果构造生成函数是许多个 \( (1+x^{k}+x^{2k}+...) \) 相乘 ...

  5. Jet Brains家族XX方法

    声明:本文转载自 https://www.jianshu.com/p/f404994e2843 2018/11/23

  6. 关于HTML标签中的一些容易忘记常用样式属性

    样式说明--样式: margin, margin-top/left/bottom/right -- 外边距; padding, padding-top/left/botton/right -- 内边距 ...

  7. Spring集成Quartz定时任务框架介绍

    在JavaEE系统中,我们会经常用到定时任务,比如每天凌晨生成前天报表,每一小时生成汇总数据等等.我们可以使用java.util.Timer结合java.util.TimerTask来完成这项工作,但 ...

  8. Java-API-Package:org.springframework.stereotype

    ylbtech-Java-API-Package:org.springframework.stereotype 1.返回顶部 1. @NonNullApi @NonNullFields Package ...

  9. HTTP-Runoob:HTPP Content-Type

    ylbtech-HTTP-Runoob:HTPP Content-Type 1.返回顶部 1. HTTP content-type Content-Type,内容类型,一般是指网页中存在的Conten ...

  10. windows下socket编程:区分shutdown()及closesocket()

    以下描述主要是针对windows平台下的TCP socket而言. 首先需要区分一下关闭socket和关闭TCP连接的区别,关闭TCP连接是指TCP协议层的东西,就是两个TCP端之间交换了一些协议包( ...