Hi, I made this function a few days ago but I don't know why I didn't posted it. It's my version of the FileFind function (without a dot lol). I made it as an alternative to the AMS File.Find function because it was blocking the application while doing the search.
I'm using luafilesystem (it's already fast) and lua lanes modules to make it really fast (finds and prints more than 1400 files in less than 3 seconds with only 256mb of ram lol) because it will be running in a new thread without blocking the application. So here is the function:
--Globals
--Example call in "On click" event of an object
-On click in other button, label, etc. or timer
I hope you like
and comments are accepted 
PD: For those who have installed lua for windows in their computers can use this code right after the example call and it will show the results in less than 1.7seconds:
I'm using luafilesystem (it's already fast) and lua lanes modules to make it really fast (finds and prints more than 1400 files in less than 3 seconds with only 256mb of ram lol) because it will be running in a new thread without blocking the application. So here is the function:
--Globals
PHP Code:
require"lanes";
function fFileFind(sPath, tSearch, bSubFolders, bCaseSensitive, tToAdd)
require"lfs";--Yeap, it's inside of the lane
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)
--Example call in "On click" event of an object
PHP Code:
tFiles = FileFind("C:\\Windows", {".dat", "*.dll", "s*.exe"}, true, false, nil);
-On click in other button, label, etc. or timer
PHP Code:
Debug.ShowWindow(true);
if tFiles.status == "done" then
if tFiles[1] then
local s = "";
Debug.Print("Files: "..#tFiles[1].."\r\n");
for each, file in pairs(tFiles[1]) do
s = s..each.." - "..file.."\r\n";
end
Debug.Print(s.."\r\n");
else
Dialog.Message("", "NoFiles");
end
elseif tFiles.status == "error" then
local a, e = tFiles:join()
Debug.Print(tostring(e));
else
Debug.Print("Status: "..tFiles.status.."\r\n");
end
I hope you like


PD: For those who have installed lua for windows in their computers can use this code right after the example call and it will show the results in less than 1.7seconds:
PHP Code:
while tFiles.status == "running" or "pending" do
if tFiles.status == "done" then
io.stderr:write("done\n")
break;
elseif tFiles.status == "pending" then
io.stderr:write("pending\n")
else
io.stderr:write(tFiles.status.."\n")
end
end
if tFiles.status == "done" then
if tFiles[1] then
print("Files: "..#tFiles[1].." in "..os.clock()-t1);
local s = "";
for each, file in pairs(tFiles[1]) do
s=s..each..":"..file.."\n";
end
print(s)
else
print("NoFiles");
end
elseif tFiles.status == "error" then
local a, e = tFiles:join()
print(tostring(e));
else
print("Status: "..tFiles.status.."\r");
end
Comment