From 52e15b3b0527a29f392b2ecb81790a3368ba59d2 Mon Sep 17 00:00:00 2001 From: neoaggelos Date: Thu, 12 Sep 2013 08:47:47 +0000 Subject: [PATCH] Small fixes in os.remove(); also added documentation --- src/base/os.lua | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/base/os.lua b/src/base/os.lua index 88d35f3c..21b7f451 100644 --- a/src/base/os.lua +++ b/src/base/os.lua @@ -266,7 +266,18 @@ end -- --- Remove files (accepts wildcards) +-- @brief An overloaded os.remove() that will be able to handle list of files, +-- as well as wildcards for files. Uses the syntax os.matchfiles() for +-- matching pattern wildcards. +-- +-- @param f A file, a wildcard, or a list of files or wildcards to be removed +-- +-- @return true on success, false and an appropriate error message on error +-- +-- @example ok, err = os.remove{"**.bak", "**.log"} +-- if not ok then +-- error(err) +-- end -- local builtin_remove = os.remove @@ -275,20 +286,23 @@ 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 + local 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 _, v in pairs(f) do - return os.remove(v) + local ok, err = os.remove(v) + if not ok then + return ok, err + end end end end - - -- -- Remove a directory, along with any contained files or subdirectories. --