Recursively copy a set of files from one directory to another in PowerShell

You guys are making this hideously complicated, when it’s really simple:

Copy-Item C:\Code\Trunk -Filter *.csproj.user -Destination C:\Code\F2 -Recurse

Will copy the Directory, creating a “Trunk” directory in F2. If you want to avoid creating the top-level Trunk folder, you have to stop telling PowerShell to copy it:

Get-ChildItem C:\Code\Trunk | Copy-Item -Destination C:\Code\F2 -Recurse -filter *.csproj.user

Leave a Comment