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庫,這個庫可以實現平台無關的文件系統訪問。
