From d832dae35c088e46e99fb1c1a374f194525a31fa Mon Sep 17 00:00:00 2001 From: Aggelos Kolaitis Date: Wed, 11 Sep 2013 13:44:17 +0300 Subject: [PATCH] Added an overloaded os.remove() that accepts a table of files and wildcards --- src/base/os.lua | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/base/os.lua b/src/base/os.lua index 4a68a6d4..4c1d3dcc 100644 --- a/src/base/os.lua +++ b/src/base/os.lua @@ -265,6 +265,34 @@ return result end +-- +-- Remove files (accepts wildcards) +-- + + local builtin_remove = os.remove + function os.remove(f) + -- in case of string, just match files + if type(f) == "string" then + local p = os.matchfiles(f) + for _, v in pairs(p) do + ok, err = builtin_remove(v) + if not ok then return ok, err end + end + -- in case of table, match files for every table entry + elseif type(f) == "table" then + + for _, ent in pairs(f) do + local p = os.matchfiles(ent) + for _, v in pairs(p) do + ok, err = builtin_remove(v) + if not ok then return ok, err end + end + end + end + end + + + -- -- Remove a directory, along with any contained files or subdirectories.