Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function zipFolder(folder)
- if #fs.list(folder) < 1 then
- error("Folder cannot be empty!")
- end
- local tData = {}
- local tNames = {}
- local tIsFolder = {}
- for k,b in pairs(fs.list(folder)) do
- local v = (folder .."/" .. b)
- if fs.isDir(v) then
- if #fs.list(v) < 1 then
- table.insert(tData, 1)
- table.insert(tIsFolder, true)
- table.insert(tNames, b)
- else
- table.insert(tData, convertFolder(v, tData, tNames, tIsFolder))
- table.insert(tIsFolder, true)
- table.insert(tNames, b)
- end
- else
- local f= io.open(v, "r")
- table.insert(tData, f:read("*a"))
- f:close()
- table.insert(tIsFolder, false)
- table.insert(tNames, b)
- end
- end
- sData = textutils.serialize(tData)
- sIsFolder = textutils.serialize(tIsFolder)
- sNames = textutils.serialize(tNames)
- local folderLoc = (folder:reverse():find("/")-1)
- local folderName = (folder:reverse():sub(1, folderLoc):reverse())
- print(folderName)
- local endData = textutils.serialize({folderName, sData, sIsFolder, sNames})
- return endData
- end
- --[[function unzipFolder(zipData, location)
- local folderName, sData, sIsFolder, sNames = unpack(textutils.unserialize(zipData))
- fs.makeDir(location .. "/" .. folderName)
- local tData = textutils.unserialize(sData)
- local tIsFolder = textutils.unserialize(sIsFolder)
- local tNames = textutils.unserialize(sNames)
- for k,v in pairs(tData) do
- if tIsFolder then
- if tData[k] == 1 then
- fs.makeDir(location .. "/" .. folderName .. "/" .. tData)
- else
- unzipFolder(tData[k], location .. "/" .. folderName)
- else
- ]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement