Advertisement
DOGGYWOOF

File checker

Feb 1st, 2024 (edited)
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. -- Check if required files and directories exist
  2. local filesToCheck = {
  3. "/disk/os/gui/",
  4. "/disk/os/home.lua",
  5. "/disk/bootloader/VA11-ILLA.lua",
  6. "/disk/boot/error"
  7. }
  8.  
  9. local diskPath = "/disk/"
  10. local recoveryPath = "/recovery/"
  11.  
  12. -- Function to check if a file or directory exists
  13. local function fileExists(path)
  14. return fs.exists(path)
  15. end
  16.  
  17. -- Function to delete a directory and its contents
  18. local function deleteDirectory(path)
  19. if fs.exists(path) then
  20. fs.delete(path)
  21. end
  22. end
  23.  
  24. -- Function to copy a directory and its contents
  25. local function copyDirectory(source, destination)
  26. if fs.exists(source) then
  27. fs.copy(source, destination)
  28. end
  29. end
  30.  
  31. -- Function to shut down the computer
  32. local function shutdownComputer()
  33. os.shutdown()
  34. end
  35.  
  36. -- Main function to check and perform actions
  37. local function checkAndHandleFiles()
  38. while true do
  39. local deleteDisk = false
  40.  
  41. for _, filePath in ipairs(filesToCheck) do
  42. if not fileExists(filePath) then
  43. deleteDisk = true
  44. break
  45. end
  46. end
  47.  
  48. if deleteDisk then
  49. if fs.exists(recoveryPath) then
  50. deleteDirectory(diskPath)
  51. copyDirectory(recoveryPath, diskPath)
  52. else
  53. shutdownComputer()
  54. end
  55. end
  56.  
  57. -- Sleep for 1 second before checking again
  58. os.sleep(1)
  59. end
  60. end
  61.  
  62. -- Run the main function
  63. checkAndHandleFiles()
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement