Advertisement
dadragon84

File Deleter

Apr 29th, 2023 (edited)
957
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.30 KB | None | 0 0
  1. fileName = "startup"
  2. if(fs.exists(fileName) == true)then
  3.     shell.run("rename startup startupDEL")
  4.     sleep(2)
  5.     shell.run("File_Deleter")
  6. end
  7. local driveLocation = ""
  8. term.clear()
  9. term.setCursorPos(1,1)
  10.  
  11. version = "1.15.2"
  12. author = "Mr John Dowe"
  13. scriptName = "Computer File Deleter"
  14. modified = " April 29, 2023"
  15.  
  16.  
  17. function listFiles(driveLocation)
  18.  
  19.     term.setTextColor( colors.cyan )
  20.     print("List of Files")
  21.     print("-------------")
  22.    
  23.     local FileList = fs.list("") --Table with all the files and directories available
  24.    
  25.    
  26.     for _, file in ipairs(FileList) do --Loop. Underscore because we don't use the key, ipairs so it's in order
  27.         local RO = fs.isReadOnly(file)
  28.         local DIR = fs.isDir(file)
  29.        
  30.         if(RO == true)then
  31.             term.setTextColor(colors.red)
  32.             print("READ ONLY: " .. file)
  33.         elseif(DIR == true)then
  34.             term.setTextColor(colors.orange)
  35.             print("DIR: " .. file)
  36.         elseif (RO == false)then
  37.             term.setTextColor( colors.white )
  38.             print("FILE: " .. file) --Print the file name
  39.         elseif(foundFile == true)then
  40.             term.setTextColor(colors.blue)
  41.             print("FOUND: rom")
  42.            
  43.         else
  44.             print("FILE NOT FOUND")
  45.         end
  46.     end --End the loop
  47.     term.setTextColor( colors.cyan )
  48.     print("-------------")
  49.     print("End of Files")
  50. end
  51.  
  52.  
  53. function deleteFile(file)
  54.     fs.delete(file)
  55.     local fileName = fs.exists(file)
  56.     return fileName
  57. end
  58.  
  59. function deleteLocalFile(driveLocation)
  60.     term.setTextColor(colors.yellow)
  61.     print("Would you like to delete ALL files? YES/NO")
  62.     local answer = read()
  63.     local answer = tostring(answer)
  64.     local answer = string.lower(answer)
  65.     local FileList = fs.list(driveLocation)
  66.     term.setTextColor(colors.white)
  67.    
  68.     for _, file in ipairs(FileList) do
  69.         local foundFile = fs.exists(file)
  70.         local RO = fs.isReadOnly(file)
  71.         local DIR = fs.isDir(file)                
  72.        
  73.         if (answer == 'yes' and RO == false and DIR == false)then
  74.             shell.run("label clear")
  75.            
  76.             for _, file in ipairs(FileList) do --Loop. Underscore because we don't use the key, ipairs so it's in order
  77.                 local fileDeleted = fs.exists(file)
  78.                 if(file == "rom" or RO == true)then
  79.                     print("SKIPPING: " .. string.upper(file))
  80.                 else
  81.                     repeat
  82.                         term.setTextColor(colors.pink)
  83.                         print("DELETING FILE: " .. string.upper(file))
  84.                         fileDeleted = deleteFile(file)
  85.                         sleep(2)
  86.                     until fileDeleted == false
  87.                 end    
  88.             end    
  89.            
  90.             term.setTextColor(colors.lime)
  91.             print("FILES DELETED!")
  92.             sleep(1)
  93.             term.setTextColor(colors.green)
  94.             print("Rebooting OS")
  95.             sleep(5)
  96.             os.reboot()
  97.         elseif(answer == 'no' and RO == true)then
  98.             term.setTextColor(colors.orange)
  99.             print("READ ONLY: " .. file)
  100.         elseif(answer == 'no' and foundFile == false)then
  101.             term.setTextColor(colors.red)
  102.             print("FILE NOT FOUND")
  103.             term.setTextColor(colors.white)
  104.         else
  105.             term.setTextColor(colors.purple)
  106.             local getLabel = shell.run("label get")
  107.             if(tostring(getLabel) == true)then
  108.                
  109.                 getLabel = shell.run("label get")
  110.                 shell.run("label set " .. getLabel )
  111.  
  112.             else
  113.                 shell.run("label set " .. "PC:" .. os.getComputerID())
  114.             end
  115.             term.setTextColor(colors.lime)
  116.             print("FILES ARE SAFE!")
  117.             sleep(1)
  118.             term.setTextColor(colors.green)
  119.             print("Rebooting OS")
  120.             sleep(5)
  121.             os.reboot()
  122.         end
  123.     end
  124.        
  125.    
  126.    
  127. end
  128.  
  129.  
  130. function printAll()
  131.     for _, match in pairs( fs.complete( "", driveLocation,true,true ) ) do print( match ) end
  132. end
  133.  
  134. function header()
  135.     print(scriptName)
  136.     print("LUA Script made by: " .. author)
  137.     term.setTextColor(colors.lime)
  138.     print("Version: "..  version)
  139.     term.setTextColor(colors.white)
  140.     print("Last Modified on:"..modified)
  141.     print("Please wait while I load myself into the system")
  142.     print("")
  143.    
  144.     sleep(10)
  145.     term.clear()
  146.     term.setCursorPos(1,1)
  147.     print("Scanning Files.... 5")
  148.     print("")
  149.     sleep(1)
  150.     term.clearLine()
  151.     term.setCursorPos(1, 1)
  152.     print("Scanning Files.... 4")
  153.     print("")
  154.     sleep(1)
  155.     term.clearLine()
  156.     term.setCursorPos(1, 1)
  157.     print("Scanning Files.... 3")
  158.     print("")
  159.     sleep(1)
  160.     term.clearLine()
  161.     term.setCursorPos(1, 1)
  162.     print("Scanning Files.... 2")
  163.     print("")
  164.     sleep(1)
  165.     term.clearLine()
  166.     term.setCursorPos(1, 1)
  167.     print("Scanning Files.... 1")
  168.     print("")
  169.     sleep(1)
  170.     term.clear()
  171.     term.setCursorPos(1, 1)
  172.     listFiles(driveLocation)
  173.    
  174.     sleep(5)
  175.    
  176.     deleteLocalFile(driveLocation)
  177.    
  178. end
  179. header()
  180.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement