Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- MOZILLA PRODUCT --
- -- ZIP PROGRAM TO CONVERT A FOLDER TO A FILE --
- local tArgs = {...}
- print("Mozilla Zipper")
- -- folder is the folder you want to zip
- function zipFolder(folder)
- local folder = folder
- local folderName = ""
- 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
- table.insert(tIsFolder, true)
- if #fs.list(v) < 1 then
- table.insert(tData, 1)
- else
- table.insert(tData, zipFolder(v, tData, tNames, tIsFolder))
- end
- else
- local f= io.open(v, "r")
- table.insert(tData, f:read("*a"))
- f:close()
- table.insert(tIsFolder, false)
- end
- table.insert(tNames, b)
- end
- sData = textutils.serialize(tData)
- sIsFolder = textutils.serialize(tIsFolder)
- sNames = textutils.serialize(tNames)
- if folder:find("/") then
- local folderLoc = (folder:reverse():find("/")-1)
- folderName = (folder:reverse():sub(1, folderLoc):reverse())
- else
- folderName = folder
- end
- local endData = textutils.serialize({folderName, sData, sIsFolder, sNames})
- return endData
- end
- if #tArgs == 2 then
- if fs.exists(tArgs[1]) then
- if fs.isDir(tArgs[1]) then
- if not fs.exists(tArgs[2]) then
- print("Zipping...")
- local fileData = zipFolder(tArgs[1])
- local f = fs.open(tArgs[2], "w")
- f.write(fileData)
- f.close()
- print("Folder zipped to " .. tArgs[2])
- else
- print("File already exists")
- end
- else
- print("Not a folder")
- end
- else
- print("Folder does not exist")
- end
- else
- print("Usage: zip <folder> <save-to>")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement