Reply -
Raw
fs.find = function(wildcard, path)
if path == nil then path = "/" end
local path = realpath(path)
local res = {}
local pathsep = "[^/]+"
for k,v in pairs(fs.list(path)) do
local subpath = fs.combine(path, v)
local m = wildcard:gmatch(pathsep)
local ok = true
for component in subpath:gmatch(pathsep) do
local sw = m()
if sw then
sw = "^" .. sw:gsub("%%", "%%%%"):gsub("*", "[^/]+") .. "$"
if not component:match(sw) then
ok = false
end
else
ok = false
end
end
if ok then
local fw = "^" .. wildcard:gsub("%%", "%%%%"):gsub("*", "[^/]+") .. "$"
if subpath:match(fw) then
table.insert(res, subpath)
end
if fs.isDir(subpath) then
for k,v in pairs(fs.find(wildcard, subpath)) do
table.insert(res, v)
end
end
end
end
return res
end