Advertisement
kreezxil

ComputerCraft Mass Copy Command

Jul 23rd, 2018
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. --[[
  2. Name: masscopy
  3. Description: Allows you to copy all of the files in one directory to another
  4. Author: Kreezxil
  5. Date: 9/14/2013
  6. ]]--
  7.  
  8. args = { ... }
  9.  
  10. if #args == 0 then
  11. print("Usage: ")
  12. print(" masscopy <source> <destination> [-f]")
  13. print("")
  14. print(" where <source> and <destination> are both directories.")
  15. print(" -f can specified and will force overwriting.")
  16. end
  17.  
  18. if args[1] ~= nil then
  19. source = shell.resolve(args[1])
  20. if not fs.isDir(source) then
  21. print("Error! Invalid source directory specified. Try again.")
  22. return
  23. end
  24. end
  25.  
  26. if args[2] ~= nil then
  27. dest = shell.resolve(args[2])
  28. if not fs.isDir(dest) then
  29. print("Creating destination directory " .. dest)
  30. fs.makeDir(dest)
  31. end
  32. end
  33.  
  34. list = fs.list(source)
  35.  
  36. for _,file in ipairs(list) do
  37. exists=false
  38. if fs.exists("/" .. dest .. "/" .. file) then
  39. exists=true
  40. if args[3] ~= "-f" then
  41. print("File " .. file .. " exists at destination! Overwrite? (y/n)")
  42. ans = read()
  43. else
  44. ans = "y" -- because -f was used
  45. end
  46. if string.find("Yy",ans) ~= nil then
  47. exists=false
  48. fs.delete("/" .. dest .. "/" .. file)
  49. end
  50. end
  51. if not exists then
  52. fs.copy("/" .. source .. "/" .. file,"/" .. dest .. "/" .. file)
  53. print("Copying file " .. file .. " to " .. "/" .. dest .. "/" .. file)
  54. else
  55. print("Not Copying file " .. file .. " to " .. dest .. " per your instructions.")
  56. end
  57. end
  58.  
  59. print("Done Copying!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement