1.618
1.618

Reputation: 339

How to copy specific files and paste to another location keeping structure?

My file structure is like this:

  • ParentFolder

    • ChildFolder_1

      • xyz.mat
      • abc.mat
      • image_xy.mat
    • ChildFolder_2

      • xyz.mat
      • abc.mat
      • image_xy.mat
    • ChildFolder_N

      • xyz.mat
      • abc.mat
      • image_xy.mat

I want to copy only image_xy.mat from each folder and paste it to another location in same hierarchy.

So far with the following reference: How to use powershell copy-item and keep structure

I tried doing this:

$source = "H:\data"
$dest = "C:\Mydata"
Get-ChildItem -Path $source | Copy-Item -Destination $dest -Recurse -Container

This just copies every file without filtering. I just need image_xy.mat How can I accomplish this in powershell?

Upvotes: 2

Views: 519

Answers (1)

D.J.
D.J.

Reputation: 4034

There is a "Filter"-parameter on the "Copy-Item" cmdlet.

Get-ChildItem -Path $source | Copy-Item -Destination $dest -Recurse -Container -filter "image_xy.mat"

Upvotes: 1

Related Questions