Advertisement
DOGGYWOOF

Doggy OS Lite Package-remover

May 27th, 2024
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. -- File Deletion Program
  2.  
  3. local function listFiles()
  4. -- Get the list of files in the /disk/packages/ directory
  5. local files = fs.list("/disk/packages/")
  6. local filteredFiles = {}
  7.  
  8. -- Filter out the restricted files
  9. for _, file in ipairs(files) do
  10. if file ~= "package-installer" and file ~= "package-remover" and file ~= "package-editor" then
  11. table.insert(filteredFiles, file)
  12. end
  13. end
  14.  
  15. return filteredFiles
  16. end
  17.  
  18. local function displayMenu(files)
  19. print("Select a file to delete:")
  20. for i, file in ipairs(files) do
  21. print(i .. ". " .. file)
  22. end
  23. print("Enter the number of the file to delete, or 'q' to quit.")
  24. end
  25.  
  26. local function deleteFile(file)
  27. -- Construct the full path
  28. local filePath = "/disk/packages/" .. file
  29. -- Delete the file
  30. fs.delete(filePath)
  31. print("Deleted: " .. file)
  32. end
  33.  
  34. local function main()
  35. while true do
  36. local files = listFiles()
  37.  
  38. if #files == 0 then
  39. print("No files available to delete.")
  40. break
  41. end
  42.  
  43. displayMenu(files)
  44.  
  45. -- Get user input
  46. local input = read()
  47.  
  48. if input == 'q' then
  49. print("Exiting...")
  50. break
  51. end
  52.  
  53. local choice = tonumber(input)
  54. if choice and choice >= 1 and choice <= #files then
  55. deleteFile(files[choice])
  56. else
  57. print("Invalid choice, please try again.")
  58. end
  59. end
  60. end
  61.  
  62. main()
  63.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement