I can extract directories with the below code just fine but arguments like "src/libbasic/*.c" aren't resulting in anything (yes there are c files in that directory), any ideas?
Code:
local function _wildcard(arg)
if type(arg) ~= "string" then return {} end
print('# _wildcard("' .. arg .. '")')
local pfx, sfx, c, sep, j
local dir, sep, d = '.', '/', 0
local list = {}
local dirs = false
for i = 1, #arg, 1 do
c = arg:sub(i,i)
if c == '*' then break end
j = i
if c == '/' or c == '\\' then
sep = c
d = i
end
end
if not c then return list end
if j then
pfx = arg:sub(1,j)
if d > 0 then dir = arg:sub(1,d-1) end
end
if not j then sfx = arg:sub(2) else sfx = arg:sub(j+2) end
if sfx then
c = sfx:sub(#sfx)
if c == '/' or c == '\\' then
dirs = true
if #sfx > 1 then
sfx = sfx:sub(1,#sfx-1)
else
sfx = nil
end
end
end
for name in lfs.dir(dir) do
local path = dir .. sep .. name
local mode = lfs.attributes(path,"mode")
local same_mode = true
if dirs == true then
same_mode = (mode == "directory")
else
same_mode = (mode ~= "directory")
end
if name ~= '.' and name ~= '..' and same_mode then
local same_pfx, same_sfx = true, true
if not pfx then path = name
else
local seg = path:sub(1,j)
same_pfx = (seg == pfx)
end
if sfx then
local val = sfx
local seg = path:sub(#path - #sfx)
same_sfx = (seg == sfx)
end
if same_pfx == true and same_sfx == true then
table.insert(list, path)
end
end
end
return list
end