Created
January 20, 2020 07:08
-
-
Save PedroAlvesV/ca5b83381f4e50eeeed53b622e6a6d04 to your computer and use it in GitHub Desktop.
snippet to delete files in the current directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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