# Copying folder contents from several folders

I have a file directory which contains folders for every month, and within those folders are several text files. In this context I would like to copy all of the text files from my January folder into a separate target folder. Then copy all of the text files within the February folder to the target folder, and so on for each month. This needs to happen sequentially and I'm not sure if I'm doing the iteration properly. I need the code to be able to run on several machines, and installing libraries on each is not possible.

Am I on the right track with the following? I'm not sure if this is the right approach to take or how to flesh this out.

function listdirectory(directory)
local i, t, popen = 0, {}, io.popen
for filename in popen('dir "'..directory..'" /b /ad'):lines() do
i = i + 1
t[i] = filename
end
return t
end

os.execute(xcopy folder_month target_folder)

• There is an extra end at the end. It it a function definition? – hjpotter92 Nov 7 '13 at 1:26
• Sorry I forgot to include the function name. That is correct, I've updated the post to reflect that – MRCLE Nov 7 '13 at 1:29
• Why do you need to do it file by file? A simple cp -r path/to/January new/path would work. – hjpotter92 Nov 7 '13 at 11:46
• This script is a smaller part of a large process. When the text files are moved into the target folder there is a separate script reading them. When that completes this script will be called again and the next months files will be needed – MRCLE Nov 7 '13 at 13:21