From c5a0077a010984ae2ca5fa959ba78ab2156dfd1e Mon Sep 17 00:00:00 2001 From: Paul Kulchenko Date: Sun, 5 May 2013 22:01:04 -0700 Subject: [PATCH] Fixed filtering out directories when spec is specified. --- src/util.lua | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/util.lua b/src/util.lua index b5b0241f01..ffa2261c0d 100644 --- a/src/util.lua +++ b/src/util.lua @@ -162,9 +162,14 @@ function FileSysHasContent(dir) end function FileSysGetRecursive(path, recursive, spec, skip) + spec = spec or "*" local content = {} local sep = string.char(wx.wxFileName.GetPathSeparator()) + -- recursion is done in all folders but only those folders that match + -- the spec are returned. This is the pattern that matches the spec. + local specmask = spec:gsub("%.", "%%."):gsub("%*", ".*").."$" + local function getDir(path, spec) local dir = wx.wxDir(path) if not dir:IsOpened() then return end @@ -173,7 +178,7 @@ function FileSysGetRecursive(path, recursive, spec, skip) while found do if not skip or not file:find(skip) then local fname = wx.wxFileName(path, file):GetFullPath() - table.insert(content, fname..sep) + if fname:find(specmask) then table.insert(content, fname..sep) end if recursive then getDir(fname, spec) end end found, file = dir:GetNext() @@ -187,7 +192,7 @@ function FileSysGetRecursive(path, recursive, spec, skip) found, file = dir:GetNext() end end - getDir(path, spec or "") + getDir(path, spec) return content end