Small fixes in os.remove(); also added documentation

This commit is contained in:
neoaggelos 2013-09-12 08:47:47 +00:00
parent e2fcf30fb4
commit 52e15b3b05

View File

@ -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.
--