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?

1
  • Filter it like this: Get-ChildItem -Path $source | where {$_.name -like "image_xy.mat"} Commented Aug 29, 2017 at 19:30

1 Answer 1

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"
Sign up to request clarification or add additional context in comments.

1 Comment

This is exactly what i wanted! Thanks @D.J.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.