12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- --[[
- Descripttion:
- version:
- Author: Neo,Huang
- Date: 2022-07-04 11:24:54
- LastEditors: Neo,Huang
- LastEditTime: 2022-07-05 10:11:47
- --]]
- local lfs = require "lfs"
- local root = {}
- -- 是否过滤文件
- local function l_is_filter_file(file)
- return file == "." or file == ".." or file == ".git" or file == ".DS_Store"
- end
- local function l_get_path_files(path, fileList, upperDir)
- path = string.rtrim(path, "/")
- if not lfs.attributes(path) then
- return
- end
- fileList = fileList or {}
- for file in lfs.dir(path) do
- if not l_is_filter_file(file) then
- local f = path .. "/" .. file
- local attr = lfs.attributes(f)
- local filename = file
- if upperDir then
- filename = string.format("%s/%s", upperDir, filename)
- end
- -- 目录递归调用
- if attr.mode == "directory" then
- l_get_path_files(f, fileList, filename)
- else
- table.insert(fileList, filename)
- end
- end
- end
- end
- -- 获取目录lua文件列表
- function root:get_path_lua_files(path)
- local fileList = {}
- l_get_path_files(path, fileList)
- local list = {}
- -- 去除.lua后缀
- for _, file in ipairs(fileList) do
- local luaFile = file:match("(.+).lua+$")
- if luaFile then
- table.insert(list, luaFile)
- end
- end
- return list
- end
- -- 获取目录文件列表
- function root:get_path_files(path)
- local fileList = {}
- l_get_path_files(path, fileList)
- return fileList
- end
- -- 创建文件路径
- function root:create_path(path)
- local attr = lfs.attributes(path)
- if not attr then
- lfs.mkdir(path)
- end
- end
- -- 获取文件修改时间
- function root:get_file_modification(file)
- return lfs.attributes(file, "modification")
- end
- return root
|