eytixis

Transfer Program (opencomputers mod - OpenOS)

Sep 10th, 2020 (edited)
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.87 KB | None | 0 0
  1. local filesystem = require("filesystem")
  2. local term = require("term")
  3. local shell = require("shell")
  4.  
  5. local function termClear()
  6.   term.clear()
  7.   term.setCursor(1,1)
  8. end
  9.  
  10. local functions = {}
  11.  
  12. local function nextLine()
  13.   local x,y = term.getCursor()
  14.   term.setCursor(1,y+1)
  15. end
  16.  
  17. local function interface()
  18.   termClear()
  19.   term.write("Choose Function: ")
  20.   local tx, ty = term.getCursor()
  21.   nextLine()
  22.   term.write("1. Clone Drive")
  23.   nextLine()
  24.   term.write("2. Copy Folder")
  25.   nextLine()
  26.   term.write("3. Remote File Transfer")
  27.   term.setCursor(tx,ty)
  28.   local choice = tonumber(io.read())
  29.   if (choice > 3 or choice < 1) then
  30.     interface()
  31.     return nil
  32.   end
  33.   functions[choice]()
  34. end
  35.  
  36. local function copy(inF, outF)
  37.   local filelist = filesystem.list(inF)
  38.   termClear()
  39.   term.write("Starting Transfer!")
  40.   nextLine()
  41.   local tf = filelist()
  42.   while tf ~= nil do
  43.     shell.execute("copy -r "..inF.."/"..tf.." "..outF)
  44.     print("Transfer of /"..tf.." folder complete!")
  45.     tf = filelist()
  46.   end
  47.   print("Transfer complete!")
  48. end
  49.  
  50. local function copyFolder()
  51.   termClear()
  52.   print("Folder Clone Protocol")
  53.   print("Enter the location of the folder you want to transfer")
  54.   local inF = io.read()
  55.   print("Enter the location of the folder you want to extract")
  56.   local outF = io.read()
  57.   copy(inF,outF)
  58. end
  59.  
  60. local function cloneDrive()
  61.   local dl = filesystem.list("//mnt")
  62.   local drives = {}
  63.   local dr = dl()
  64.   termClear()
  65.   repeat
  66.     table.insert(drives, dr)
  67.     dr = dl()
  68.   until dr == nil
  69.   for key, amount in pairs(drives) do
  70.     print(key..". "..amount)
  71.   end
  72.   term.write("from: ")
  73.   local c1 = io.read()
  74.   term.write("to: ")
  75.   local c2 = io.read()
  76.   copy("//mnt/"..drives[tonumber(c1)],"//mnt/"..drives[tonumber(c2)])
  77. end
  78.  
  79. functions[1] = cloneDrive
  80. functions[2] = copyFolder
  81. functions[3] = require("rftp")
  82.  
  83. interface()
Add Comment
Please, Sign In to add comment