Advertisement
HarvDad

copyall

Mar 14th, 2014
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. -- copyall: Version 0.1
  2. -- Copys all files from source to destination
  3. -- Written by HarvDad, March 2014
  4.  
  5. args = {...}
  6. nArgs = #args
  7.  
  8. usage = "Usage: copyall <src directory><dst directory>"
  9.  
  10. if (nArgs == 0 or args[1]== "help") then
  11. print("Copys all files from source to destination")
  12. print(usage)
  13. return
  14. end
  15.  
  16. if nArgs ~= 2 then
  17. print(usage)
  18. return
  19. end
  20.  
  21. src = args[1]
  22. dst = args[2]
  23.  
  24. list = fs.list(src)
  25.  
  26. for i=1,#list do
  27. if not fs.isDir(list[i]) then
  28. filename = list[i]
  29. -- print(filename)
  30. firstchar = string.sub(filename, 1, 1)
  31. -- print("firstchar = ", firstchar)
  32. if firstchar ~= "." then
  33. srcpath = src .. "/" .. filename
  34. dstpath = dst .. "/" .. filename
  35. print("Copying ", srcpath, " to ", dstpath)
  36. if fs.exists(dstpath) then
  37. fs.delete(dstpath)
  38. end
  39. fs.copy(srcpath, dstpath)
  40. else
  41. print("Ignoring: ", filename)
  42. end
  43. end
  44. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement