Posted 14 September 2013 - 02:22 PM
Name: masscopy
Description: copy all files in one folder to another folder, supports overwriting and forced-overwriting as well as destination folder creation. Did I mention recursion?
Link to get file:
http://turtlescripts.com/project/gjdhi8-Mass-Copy
Video of program:
http://www.youtube.com/watch?v=o5i6ODxxF2c&feature=youtu.be
Note: Code below is not always up to date whereas the turtlescripts code will be.
Description: copy all files in one folder to another folder, supports overwriting and forced-overwriting as well as destination folder creation. Did I mention recursion?
Link to get file:
http://turtlescripts.com/project/gjdhi8-Mass-Copy
Video of program:
http://www.youtube.com/watch?v=o5i6ODxxF2c&feature=youtu.be
Note: Code below is not always up to date whereas the turtlescripts code will be.
Spoiler
--[[
Name: masscopy
Description: Allows you to copy all of the files in one directory to another
Author: Kreezxil
Date: 9/14/2013
]]--
args = { ... }
if #args == 0 then
print("Usage: ")
print(" masscopy <source> <destination> [-f]")
print("")
print(" where <source> and <destination> are both directories.")
print(" -f can specified and will force overwriting.")
end
if args[1] ~= nil then
source = shell.resolve(args[1])
if not fs.isDir(source) then
print("Error! Invalid source directory specified. Try again.")
return
end
end
if args[2] ~= nil then
dest = shell.resolve(args[2])
if not fs.isDir(dest) then
print("Creating destination directory " .. dest)
fs.makeDir(dest)
end
end
list = fs.list(source)
for _,file in ipairs(list) do
exists=false
if fs.exists("/" .. dest .. "/" .. file) then
exists=true
if args[3] ~= "-f" then
print("File " .. file .. " exists at destination! Overwrite? (y/n)")
ans = read()
else
ans = "y" -- because -f was used
end
if string.find("Yy",ans) ~= nil then
exists=false
fs.delete("/" .. dest .. "/" .. file)
end
end
if not exists then
fs.copy("/" .. source .. "/" .. file,"/" .. dest .. "/" .. file)
print("Copying file " .. file .. " to " .. "/" .. dest .. "/" .. file)
else
print("Not Copying file " .. file .. " to " .. dest .. " per your instructions.")
end
end
print("Done Copying!")