Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fs.find = function(path)
- local pathParts, results, curfolder = {}, {}, "/"
- for part in path:gmatch("[^/]+") do pathParts[#pathParts + 1] = part:gsub("*", "[^/]*") end
- if #pathParts == 0 then return {} end
- local prospects = fs.list(curfolder)
- for i = 1, #prospects do prospects[i] = {["parent"] = curfolder, ["depth"] = 1, ["name"] = prospects[i]} end
- while #prospects > 0 do
- local thisProspect = table.remove(prospects, 1)
- local fullPath = fs.combine(thisProspect.parent, thisProspect.name)
- if thisProspect.name == thisProspect.name:match(pathParts[thisProspect.depth]) then
- if thisProspect.depth == #pathParts then
- results[#results + 1] = fullPath
- elseif fs.isDir(fullPath) and thisProspect.depth < #pathParts then
- local newList = fs.list(fullPath)
- for i = 1, #newList do prospects[#prospects + 1] = {["parent"] = fullPath, ["depth"] = thisProspect.depth + 1, ["name"] = newList[i]} end
- end
- end
- end
- return results
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement