Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- ZIPPER --
- -- VERIFICATION STAMP: Z1p 4rch1v3 [4PPR0V3D] --
- local tArgs = { ... }
- workingDir = ("/.ziptool")
- function getDir(dir)
- local slashLoc = nil
- for i = 2, string.len(dir) do
- local b = (i*-1)
- if string.sub(dir, b, b) == "/" then
- slashLoc = (string.len(dir) - i)
- local eDir = string.sub(dir, 1, slashLoc)
- local eName = string.sub(dir, slashLoc+1, -1)
- return eDir, eName
- end
- end
- return nil
- end
- function zipDir(toZip, saveTo)
- local f = nil
- local fTable = {}
- local nFiles = 0
- local nFolders = 0
- local nFileNames = {}
- local fData = nil
- local skip = false
- local listFiles = fs.list(toZip)
- if listFiles[1] == nil then
- return
- else
- for i = 1, #listFiles do
- if listFiles[i] == "disk" and toZip == "/" and fs.isDir("disk") then
- local skip = true
- elseif listFiles[i] == "disk2" and toZip == "/" and fs.isDir("disk2") then
- local skip = true
- elseif listFiles[i] == "disk3" and toZip == "/" and fs.isDir("disk3") then
- local skip = true
- elseif listFiles[i] == "rom" and toZip == "/" then
- local skip = true
- else
- local skip = false
- end
- if not fs.isDir(toZip .. listFiles[i]) then
- table.insert(nFileNames, listFiles[i])
- nFiles = nFiles+1
- f = io.open(toZip, "r")
- fData = f:read("*a")
- f:close()
- table.insert(fTable, fData)
- elseif not skip then
- print("Folder")
- table.insert(nFileNames, listFiles[i])
- nFolders = nFolders+1
- rFile = zipDir(toZip .. listFiles[i] .. "/", workingDir)
- f = io.open(rFile, "r")
- fData = f:read("*a")
- f:close()
- table.insert(fTable, fData)
- print("Folder Success")
- end
- end
- table.insert(fTable, 1, "Z1p 4rch1v3 [4PPR0V3D]")
- local fNames = textutils.serialize(nFileNames)
- local fWrite = textutils.serialize(fTable)
- if saveTo == nil then
- saveTo = toZip
- end
- f = io.open(toZip .. ".zip", "w")
- f:write(fWrite .. "\n" .. fNames)
- f:close()
- return (toZip .. ".zip"), nFiles, nFolders
- end
- end
- if not fs.exists("/.ziptool") then
- fs.makeDir("/.ziptool")
- end
- if #tArgs > 0 and #tArgs < 3 then
- print("Zipping...")
- local toZip = nil
- if string.sub(tArgs[1], string.len(tArgs[1]), string.len(tArgs[1])) == "/" then
- toZip = tArgs[1]
- else
- toZip = (tArgs[1] .. "/")
- end
- if tArgs[2] then
- if string.sub(tArgs[2], string.len(tArgs[2]), string.len(tArgs[2])) == "/" then
- saveTo = tArgs[2]
- else
- saveTo = (tArgs[2] .. "/")
- end
- end
- zipFile, nFiles, nFolders = zipDir(toZip, saveTo)
- print("Zipped " .. nFiles .. " files and " .. nFolders .. " folders")
- print("Zipped as " .. zipFile)
- else
- print("Usage: <command> <target> [savein]")
- print("Ex: ziptool MyFolder SaveHere")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement