Copy all files in a tree structure into one destination folder
This is an old approach which I have used in SSIS Packages to flattern a directory tree into one source folder.
I wanted to retrieve all CSV files in a folder structure and copy them into a single folder so that a SSIS package can then process them….I know some people might think, well why don’t you just tick the box that says “Traverse Subfolders” in a for-each component – but I needed the files in a single folder for humans too in this case.
First Approach – DOS/CMD Prompt
for /r C:\SourceRootFolder %f in (*.csv) do @copy "%f" C:\DestinationFolder
Second Approach – Powershell
Get-ChildItem C:\SourceRootFolder -Recurse -Filter "*.csv" | ` Copy-Item -destination C:\DestinationFolder
Either of these commands can be executed from within an Execute Process Task in SSIS, or just as commands from either CMD-Prompt or PowerShell Prompt.