Advertisement
1lann

convert-folder

Sep 30th, 2012
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.55 KB | None | 0 0
  1. function zipFolder(folder)
  2.     if #fs.list(folder) < 1 then
  3.         error("Folder cannot be empty!")
  4.     end
  5.     local tData = {}
  6.     local tNames = {}
  7.     local tIsFolder = {}
  8.  
  9.     for k,b in pairs(fs.list(folder)) do
  10.         local v = (folder .."/" .. b)
  11.         if fs.isDir(v) then
  12.             if #fs.list(v) < 1 then
  13.                 table.insert(tData, 1)
  14.                 table.insert(tIsFolder, true)
  15.                 table.insert(tNames, b)
  16.             else
  17.                 table.insert(tData, convertFolder(v, tData, tNames, tIsFolder))
  18.                 table.insert(tIsFolder, true)
  19.                 table.insert(tNames, b)
  20.             end
  21.         else
  22.             local f= io.open(v, "r")
  23.             table.insert(tData, f:read("*a"))
  24.             f:close()
  25.             table.insert(tIsFolder, false)
  26.             table.insert(tNames, b)
  27.         end
  28.     end
  29.     sData = textutils.serialize(tData)
  30.     sIsFolder = textutils.serialize(tIsFolder)
  31.     sNames = textutils.serialize(tNames)
  32.     local folderLoc = (folder:reverse():find("/")-1)
  33.     local folderName = (folder:reverse():sub(1, folderLoc):reverse())
  34.     print(folderName)
  35.     local endData = textutils.serialize({folderName, sData, sIsFolder, sNames})
  36.     return endData
  37. end
  38.  
  39. --[[function unzipFolder(zipData, location)
  40.     local folderName, sData, sIsFolder, sNames = unpack(textutils.unserialize(zipData))
  41.     fs.makeDir(location .. "/" .. folderName)
  42.     local tData = textutils.unserialize(sData)
  43.     local tIsFolder = textutils.unserialize(sIsFolder)
  44.     local tNames = textutils.unserialize(sNames)
  45.     for k,v in pairs(tData) do
  46.         if tIsFolder then
  47.             if tData[k] == 1 then
  48.                 fs.makeDir(location .. "/" .. folderName .. "/" .. tData)
  49.             else
  50.             unzipFolder(tData[k], location .. "/" .. folderName)
  51.         else
  52. ]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement