MudkipTheEpic

Disk Transfer 1.0

Dec 29th, 2012
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. local tArgs = { ... }
  2. local files = 0
  3.  
  4. -- Get all the files in the directory
  5. local sDir = shell.dir()
  6. if tArgs[1] == "0" then
  7. local copy = false
  8. elseif tArgs[1] == "1" then
  9. local copy = true
  10. else
  11. error("Invalid argument. '1' to copy, or '0' to not.")
  12. end
  13.  
  14. -- Sort into dirs/files.
  15. local tAll = fs.list( sDir )
  16. local tFiles = {}
  17. local tDirs = {}
  18.  
  19. term.clear()
  20. term.setCursorPos(1,1)
  21. print("What would you like to save this transfer as?")
  22. local input = read()
  23. if fs.exists("disk/transfer"..input) then
  24. error("Transfer already exists.")
  25. else
  26. id = input
  27. end
  28.  
  29. for n, sItem in pairs( tAll ) do
  30. if string.sub( sItem, 1, 1 ) ~= "." then
  31. local sPath = fs.combine( sDir, sItem )
  32. if fs.isReadOnly( sPath ) ~= true then
  33. if fs.isDir("disk") then
  34. fs.makeDir("disk/transfer"..id)
  35. if copy == false then
  36. fs.move( sPath, "disk/transfer"..id.."/"..sPath) -- Move the files to disk.
  37. files = files + 1
  38. else
  39. fs.copy( sPath, "disk/transfer"..id.."/"..sPath)
  40. files = files + 1
  41. end
  42. else
  43. error("No disk inserted.") -- Error: No disk.
  44. end
  45. end
  46. end
  47. end
  48. files = tostring(files)
  49. print("Transfered "..files.." files to disk/transfer"..id.."!")
Advertisement
Add Comment
Please, Sign In to add comment