--------------- require"lanes"; require"lfs"; --------------- function fFileFind(sPath, tSearch, bSubFolders, bCaseSensitive, tToAdd) function FileFindA(sPath, tSearch, bSubFolders, bCaseSensitive, tToAdd) local tS = (type(tSearch=="table")) and tSearch or {""}; local bC = bCaseSensitive or false; if #tS > 0 then for x, y in pairs(tS) do local a = (bC==true) and y or string.gsub(y, "(.)", function(s) return string.lower(s) end); a = string.gsub(a, "(.)*(.)", function(s, sa) return "%b"..s..sa end); a = string.gsub(a, "*(..)", function(s) return "%b"..s end); a = string.gsub(a, "(..)(.)%.", function (s, ss) return (s=="%b") and s..ss.."." or s..ss.."%." end) a = string.gsub(a, "^%.", "%%.") tS[x] = string.gsub(a, "?", "."); end end return FileFindB(sPath, tS, bSubFolders, bC, tToAdd); end function FileFindB(sPath, tSearch, bSubFolders, bCaseSensitive, tToAdd) local tReturn = (type(tToAdd)=="table") and tToAdd or {}; local tDirs = {}; if lfs.chdir(sPath) then for x in lfs.dir(sPath) do if x ~= "." and x ~= ".." then if lfs.attributes(x, "mode") == "file" then for y, z in pairs(tSearch) do local a = (bCaseSensitive==false) and x or string.gsub(x, "(.)", function(s) return string.lower(s) end); if string.find(a, z) then table.insert(tReturn, #tReturn+1, sPath.."\\"..x); end end elseif lfs.attributes(x, "mode") == "directory" then if bSubFolders then table.insert(tDirs, #tDirs+1, sPath.."\\"..x); end end end end if #tDirs > 0 and bSubFolders then for x, y in pairs(tDirs) do FileFindB(y, tSearch, true, bCaseSensitive, tReturn); end end return (#tReturn>0) and tReturn or nil; else return nil; end end return FileFindA(sPath, tSearch, bSubFolders, bCaseSensitive, tToAdd) end local FileFind = lanes.gen("*", fFileFind) -- Llamada: --tFiles = FileFind("C:\\Windows", {".dat", "*.dll", "s*.exe"}, true, false, nil);