Saving various files in different folders into one single folder using powershell


I have a 3 folders here with 3 files.

Within each there is a csv file, I want to save them all into a destination folder without having to open each folder and drag and drop the file into the destination folder.

I attempted this.

$destination = "C:\Desktop\Test"
$sourcefiles = get-childitem -recurse
foreach ($file in $sourcefiles)
    Copy-Item $file.FullName -Destination "$destination\$file.Name"

When I do that, I get the folders copied, which is really cool, but no file.

Any help is appreciated

Looking for something like this…FileA resides in TestA, FileB resides in TestB.. I have several hundred of these and I have to save them into a backup location

>Solution :

You are looking to copy the folders and it’s contents to a new destination, so, simply target the folders and then use Copy-Item -Recurse:

Get-ChildItem path\to\testfolders -Directory | Copy-Item -Destination "C:\Desktop\Test" -Recurse

Leave a ReplyCancel reply