There are a lot of instructions how to copy certain files from one folder to another folder and preserving the folder structure. I can do this with xcopy [srcFolder][Filename] [DestFolder] /S /K /Y.
However, what I need is searching for a certain folder name and then copy that folder along with all it's content to the destination folder. So let's say I have the following:
SrcFolder
-Folder 1
-MySubfolder
-File1_1.txt
-File1_2.jpg
-AnotherSubfolder
-File1_3.txt
-Folder 2
-MySubfolder
-File2_1.txt
-File2_2.jpg
-AnotherSubfolder
-File2_3.txt
Now I would like to copy all "MySubfolder" folders incl their content. So at the end my target directory will look like this
DstFolder
-Folder 1
-MySubfolder
-File1_1.txt
-File1_2.jpg
-Folder 2
-MySubfolder
-File2_1.txt
-File2_2.jpg
How can I achieve this? Note that I am on Windows 7 so I don't have access to robocopy
Get-ChildItem
using-include "*MySubfolder*" -recurse
or something along those lines. Should be a simple trivial matter to get setup with PowerShell.foreach { copy-item -Path $_ $dst -recurse -force }
and don't forget about-ErrorAction SilentlyContinue
too as it might help with that error. Otherwise you can wrap in anIf(!(Test-Path $_)){ copy-item -Path $_ $dst -recurse -force }
or something like that. Good job, keep digging at it, you are doing great! This answer might be somewhat helpful too for those things I mention: superuser.com/questions/1562774/….