Advertisement
programcreator

Compress

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