require "io" require "lfs" ---------------------------------------------------------------------------------- --It will return a table that contents all the file paths in the rootpath function getpathes(rootpath, pathes) pathes = pathes or {} for entry in lfs.dir(rootpath) do if entry ~= '.' and entry ~= '..' then local path = rootpath .. '\\' .. entry local attr = lfs.attributes(path) assert(type(attr) == 'table') if attr.mode == 'directory' then getpathes(path, pathes) else table.insert(pathes, path) end end end return pathes end
传入一个根目录路径,递归该路径下的所有子目录,返回所有文件全路径。
用到了lua的lfs库,这个库可以实现平台无关的文件系统访问。
lua lfs库的使用,递归获取子文件路径
最新推荐文章于 2024-06-29 21:02:37 发布