2

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?

Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
1.618
  • 339
  • 2
  • 14

1 Answers1

1

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

Get-ChildItem -Path $source | Copy-Item -Destination $dest -Recurse -Container -filter "image_xy.mat"
D.J.
  • 3,644
  • 2
  • 15
  • 22