Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local os=require("os")
- local component=require("component")
- local shell=require("shell")
- local filesystem=require("filesystem")
- local math=require("math")
- local term=require("term")
- local tape=component.getPrimary("tape_drive")
- local args,flags=shell.parse(...)
- --functions--
- local function round(num,idp)
- local mult=10^(idp or 0)
- return math.floor(num*mult+.5)/mult
- end
- local function lerror(text)
- error(text)
- end
- local function writeToTape(filepath)
- local filesize=filesystem.size(filepath)
- local file=io.open(filepath,"fb")
- local writed=0
- local lastpercent=""
- local percent=""
- local text=nil
- local x,y=term.getCursor()
- local offset=#(filepath..": ")+1
- term.write(filepath..": ")
- text=file:read()
- if not flags["M"] then
- tape.write("[START]")
- --tape.write("[FILENAME "..filepath.." ]")
- tape.write("[FILESIZE "..tostring(filesize).." ]")
- end
- while text~=nil do
- x,y=term.getCursor()
- os.sleep(0)
- tape.stop()
- tape.write(text)
- writed=writed+#text
- if flags["b"] then
- term.setCursor(offset,y)
- term.write(tostring(writed).."/"..tostring(filesize))
- else
- term.setCursor(offset,y)
- term.write(" ")
- percent=tostring(round(writed/filesize*100,1))
- term.setCursor(offset+4-#percent,y)
- term.write(percent)
- term.setCursor(offset+4,y)
- term.write("%")
- end
- text=file:read(10240)
- if text~=nil then
- text=text.."\n"
- end
- end
- if not flags["M"] then
- tape.write("[END]")
- end
- term.setCursor(offset,y)
- if flags["b"] then
- print(tostring(writed).."/"..tostring(filesize))
- else
- print(" 100%")
- end
- end
- function canonPath(path)
- if string.sub(args[1],1,1)=="/" then
- return filesystem.canonical(path)
- else
- return filesystem.canonical(os.getenv("PWD").."/"..path)
- end
- end
- ----
- if args[1]==nil then
- file=os.getenv("PWD")
- else
- for i=1,#args do
- if not filesystem.exists(canonPath(args[i])) and not filesystem.exists(canonPath(args[i])..".dfpwm") then
- lerror("No such file or directory: "..args[i])
- end
- end
- end
- if filesystem.isDirectory(args[1] or file) then
- for filename in filesystem.list(file) do
- if string.find(filename,".dfpwm$") and not filesystem.isDirectory(filename) and not exitl then
- writeToTape(file..filename)
- end
- end
- print("Done!")
- else
- local filept=""
- for i=1,#args do
- filept=canonPath(args[i])
- if not filesystem.exists(filept) and filesystem.exists(filept..".dfpwm") and not filesystem.isDirectory(filept..".dfpwm") then
- filept=filept..".dfpwm"
- end
- writeToTape(filept)
- end
- print("Done!")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement