14

I was trying the accepted solution here: https://serverfault.com/questions/194827/writing-a-powershell-script-to-copy-files-with-certain-extension-from-one-folder/223014#223014 But it doesnt work, and my comment on the accepted solution is not getting a response.

I am trying to copy all pictures I have in my Pictures drive (only PNG, JPG, without the video files) to a different drive, but having no luck.

Ideally I want to copy recursively, but to a flat destination (not mirroring the source sub-directories)

I tried this command: Copy-Item -path "C:\Users\genadi\Pictures\" -include "*.JPG", "*.PNG" -Destination "D:\" with and without -recurse but nothing happens.

Ideally, I want a script that will 1) reduce original size of all JPG and PNG pictures (including all sub-folders) and 2) copy the reduced size to specified destination.

Currently my originals are about 20GB, I need to fit them on a flash drive for display/printing purposes etc. and easily repeat this when needed (hence why script would be nice).

1 Answer 1

26

That's because the object name returned by the cmdlet doesn't include the extension, you need to append \*. I'm not sure if Copy-Item allows you to "collapse" the destination directory, so I would use Get-ChildItem with -Recurse and pipe it to Copy-Item

Get-ChildItem -Path "C:\Users\genadi\Pictures\*" -Include *.jpg,*.png -Recurse | Copy-Item -Destination D:\
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .