Advertisement
DOGGYWOOF

Secure erase

Jul 7th, 2024 (edited)
8
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. -- Function to check if a file contains a specific word or number
  2. local function fileContains(filePath, pattern)
  3. local file = fs.open(filePath, "r")
  4. if file then
  5. local content = file.readAll()
  6. file.close()
  7. if string.find(content, pattern) then
  8. return true
  9. end
  10. end
  11. return false
  12. end
  13.  
  14. -- Function to recursively search through directories for files containing the pattern
  15. local function searchDirectory(directoryPath, pattern, filesToDelete)
  16. for _, item in ipairs(fs.list(directoryPath)) do
  17. local itemPath = directoryPath .. "/" .. item
  18. if fs.isDir(itemPath) then
  19. searchDirectory(itemPath, pattern, filesToDelete)
  20. else
  21. if item ~= "System" and fileContains(itemPath, pattern) then
  22. table.insert(filesToDelete, itemPath)
  23. end
  24. end
  25. end
  26. end
  27.  
  28. -- Main program
  29. local function main()
  30. local searchPattern = "yourWordOrNumber" -- Change this to the word or number you are searching for
  31. local directoriesToSearch = {"/disk", "/recovery"}
  32. local filesToDelete = {}
  33.  
  34. -- Iterate through the specified directories
  35. for _, directory in ipairs(directoriesToSearch) do
  36. if fs.exists(directory) and fs.isDir(directory) then
  37. searchDirectory(directory, searchPattern, filesToDelete)
  38. end
  39. end
  40.  
  41. -- If no files found, inform the user and exit
  42. if #filesToDelete == 0 then
  43. print("No files containing the pattern were found.")
  44. return
  45. end
  46.  
  47. -- Show the list of files to delete
  48. print("The following files contain the pattern and will be deleted:")
  49. for _, file in ipairs(filesToDelete) do
  50. print(file)
  51. end
  52.  
  53. -- Ask for confirmation
  54. print("Do you want to delete these files? (yes/no)")
  55. local response = read()
  56.  
  57. if response == "yes" then
  58. -- Delete the files
  59. for _, file in ipairs(filesToDelete) do
  60. fs.delete(file)
  61. end
  62. print("Files deleted.")
  63. else
  64. print("Deletion aborted.")
  65. end
  66. end
  67.  
  68. -- Run the main program
  69. main()
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement