Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function usage()
- print("Usage: clone SRC DST")
- print("SRC is the side you want to copy from.")
- print("DST is the side you want to copy to.")
- print("Sides are left, right, front, back,")
- print("top, bottom.")
- end
- local args = {...}
- if #args ~= 2 then
- return usage()
- end
- local src = args[1]
- local dst = args[2]
- if not disk.isPresent(src) then
- return print("Source disk not present ("..src..")")
- end
- if not disk.isPresent(dst) then
- return print("Destination disk not present ("..dst..")")
- end
- if not disk.hasData(src) then
- return print("Source disk is not a data disk ("..src..")")
- end
- if not disk.hasData(dst) then
- return print("Destination disk is not a data disk ("..dst..")")
- end
- disk.setLabel(dst, disk.getLabel(src))
- src = disk.getMountPath(src)
- dst = disk.getMountPath(dst)
- local function recursiveErase(path)
- for _,v in ipairs(fs.list(path)) do
- local path2 = path.."/"..v
- if fs.isDir(path2) then
- recursiveErase(path2)
- end
- fs.delete(path2)
- end
- end
- local function recursiveCopy(src, dst)
- for _,v in ipairs(fs.list(src)) do
- local src2 = src.."/"..v
- local dst2 = dst.."/"..v
- if fs.isDir(src2) then
- fs.makeDir(dst2)
- recursiveCopy(src2, dst2)
- else
- local srcf = fs.open(src2, "r")
- local dstf = fs.open(dst2, "w")
- dstf.write(srcf.readAll())
- dstf.close()
- srcf.close()
- end
- end
- end
- recursiveErase(dst)
- recursiveCopy(src, dst)
Advertisement
Add Comment
Please, Sign In to add comment