Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

I have a 3 folders here with 3 files.

enter image description here

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

enter image description here

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

enter image description here

>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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading