This repository has been archived on 2024-04-19. You can view files and clone it, but cannot push or open issues or pull requests.
FREAX/bin/rm

31 lines
921 B
Text
Raw Permalink Normal View History

2022-07-18 19:33:40 +02:00
local args = table.pack(...)
if args.n < 1 then
local programName = "rm"
print("Usage: " .. programName .. " <paths>")
return
end
for i = 1, args.n do
local files = fs.find(shell.resolve(args[i]))
if #files > 0 then
for _, file in ipairs(files) do
if fs.isReadOnly(file) then
printError("Cannot delete read-only file /" .. file)
elseif fs.isDriveRoot(file) then
printError("Cannot delete mount /" .. file)
if fs.isDir(file) then
print("To delete its contents run rm /" .. fs.combine(file, "*"))
end
else
local ok, err = pcall(fs.delete, file)
if not ok then
printError((err:gsub("^pcall: ", "")))
end
end
end
else
printError(args[i] .. ": No matching files")
end
end