Advertisement
Ale2610

Untitled

Sep 24th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. local args = {...}
  2. if not args[1] then
  3. local disc = "/disk"
  4. end
  5. if not args[2] then
  6. local output = "diskBackup"
  7. end
  8.  
  9. --[[
  10. Filesystem
  11. explorer
  12. by Creator
  13. ]]--
  14. local ignore = {}
  15.  
  16. local filesystem = {}
  17.  
  18. local function readFile(path)
  19. local file = fs.open(path,"r")
  20. local variable = file.readAll()
  21. file.close()
  22. return variable
  23. end
  24.  
  25. local function isNotBanned(path)
  26. for i,v in pairs(ignore) do
  27. if v == path then
  28. return false
  29. end
  30. end
  31. return true
  32. end
  33.  
  34. local function explore(dir)
  35. local buffer = {}
  36. local sBuffer = fs.list(dir)
  37. for i,v in pairs(sBuffer) do
  38. sleep(0.05)
  39. if isNotBanned(dir.."/"..v) then
  40. if fs.isDir(dir.."/"..v) then
  41. if v ~= ".git" then
  42. print("Compressing directory: "..dir.."/"..v)
  43. buffer[v] = explore(dir.."/"..v)
  44. end
  45. else
  46. print("Compressing file: "..dir.."/"..v)
  47. buffer[v] = readFile(dir.."/"..v)
  48. end
  49. end
  50. end
  51. return buffer
  52. end
  53.  
  54. append = [[
  55. local function writeFile(path,content)
  56. local file = fs.open(path,"w")
  57. file.write(content)
  58. file.close()
  59. end
  60. function writeDown(input,dir)
  61. for i,v in pairs(input) do
  62. if type(v) == "table" then
  63. writeDown(v,dir.."/"..i)
  64. elseif type(v) == "string" then
  65. writeFile(dir.."/"..i,v)
  66. end
  67. end
  68. end
  69.  
  70. args = {...}
  71. if #args == 0 then
  72. print("Please input a destination folder.")
  73. else
  74. writeDown(inputTable,args[1])
  75. end
  76.  
  77. ]]
  78.  
  79. local filesystem = explore(disc)
  80. local file = fs.open(output,"w")
  81. file.write("inputTable = "..textutils.serialize(filesystem)) --[[.."\n\n\n\n\n\n\n\n\n"..append]]
  82. file.close()
  83.  
  84. if data and data["deflate"] and data["inflate"] then
  85. local f = fs.open(output,"r")
  86. local dat = f.readAll()
  87. f.close()
  88. local f = fs.open(output,"w")
  89. f.write(data.deflate(dat))
  90. f.close()
  91. end
  92. print("Output: "..output)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement