Skip to content

Instantly share code, notes, and snippets.

@PedroAlvesV
Created January 20, 2020 07:08
Show Gist options
  • Save PedroAlvesV/ca5b83381f4e50eeeed53b622e6a6d04 to your computer and use it in GitHub Desktop.
Save PedroAlvesV/ca5b83381f4e50eeeed53b622e6a6d04 to your computer and use it in GitHub Desktop.
snippet to delete files in the current directory
local function contains(t, v)
for index, value in ipairs(t) do
if value == v then
return true
end
end
return false
end
local protected = {
".classpath",
".project",
"collatz.c",
"collatz.o",
"main.lua",
"sandbox.lua"
}
local found = {}
local delete = {}
for name in io.popen([[dir "" /b]]):lines() do
table.insert(found, name)
end
for _, value in ipairs(found) do
if not contains(protected, value) then
table.insert(delete, value)
end
end
for _, filename in ipairs(delete) do
print("Deleting "..filename.." (unless it is a folder)")
os.remove(filename)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment