Advertisement
kreezxil

[CC 1.53] masscopy

Sep 14th, 2013
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.35 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>")
  13.     print("")
  14.     print("  where <source> and <destination> are both directories.")
  15. end
  16.  
  17. if args[1] ~= nil then
  18.     source = shell.resolve(args[1])
  19.     if not fs.isDir(source) then
  20.         print("Error! Invalid source directory specified. Try again.")
  21.         return
  22.     end
  23. end
  24.  
  25. if args[2] ~= nil then
  26.     dest = shell.resolve(args[2])
  27.     if not fs.isDir(dest) then
  28.         print("Creating destination directory " .. dest)
  29.         fs.makeDir(dest)
  30.     end
  31. end
  32.  
  33. list = fs.list(source)
  34.  
  35. for _,file in ipairs(list) do
  36.     exists=false
  37.     if fs.exists(dest .. "/" .. file) then
  38.         exists=true
  39.         print("File " .. file .. " exists at destination! Overwrite? (y/n)")
  40.         ans = read()
  41.         if string.find("Yy",ans) ~= nil then
  42.             exists=false
  43.             fs.delete(dest .. "/" .. file)
  44.         end
  45.     end
  46.     if not exists then
  47.         fs.copy("/" .. source .. "/" .. file,dest)
  48.         print("Copying file " .. file .. " to " .. dest)
  49.     else
  50.         print("Not Copying file " .. file .. " to " .. dest .. " per your instructions.")
  51.     end
  52. end
  53.  
  54. print("Done Copying!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement