Published by:amaljabur@gmail.com
-- delete_test_folder.lua
-- Permanently deletes a folder (and all its contents) ONLY if its path includes "test_vm".
-- Safety: requires repeating the exact path and typing DELETE as final confirmation.
local function lower(s) return (s or ""):lower() end
local function trim(p) return (p or ""):gsub("[\\/]+$", "") end
local function is_dangerous(p)
if not p or p == "" then return true end
local lp = lower(p)
-- refuse root drives like "C:\" or "/"
if lp:match("^%a:[\\/]?$") or lp == "/" then return true end
-- refuse known system directories
if lp:find("\\windows") or lp:find("program files") or lp:find("system32") then
return true
end
return false
end
local function contains_test_vm(p)
return lower(p):find("test_vm") ~= nil
end
print("=== STRICT TEST FOLDER DELETE ===")
print("This WILL PERMANENTLY DELETE the folder you provide (and everything inside it).")
io.write("Enter the FULL absolute path to the folder to DELETE (e.g. C:\\test_vm_folder): ")
local dir = io.read()
dir = trim(dir)
if not dir or dir == "" then
print("No path provided. Exiting.")
os.exit(1)
end
if is_dangerous(dir) then
print("Refusing to operate on that directory for safety.")
os.exit(1)
end
if not contains_test_vm(dir) then
print("Refusing: path must include the substring 'test_vm' (case-insensitive).")
os.exit(1)
end
print("\nYou entered:", dir)
io.write("Type the FULL PATH AGAIN to confirm (case-sensitive): ")
local conf = io.read()
if conf ~= dir then
print("Confirmation mismatch — aborting.")
os.exit(0)
end
io.write("\nFINAL confirmation: type DELETE (ALL CAPS) to PERMANENTLY remove the folder: ")
local final = io.read()
if final ~= "DELETE" then
print("Aborted by user.")
os.exit(0)
end
-- Execute deletion (Windows command)
local rd_cmd = string.format('rmdir /s /q "%s"', dir)
print("\nExecuting full deletion command...")
os.execute(rd_cmd)
print("\nDone. The folder and all its contents should be permanently deleted.")
print("If some files were in use or protected, they may not have been removed.")
Created On: 10/6/2025