Search code examples
powershellpipecopy-item

Append new extension when copying files


I use the following command in order to locate the files that are greater than 900KB in a specific folder:

Get-ChildItem -path C:\[some folder] | where { ($_.Length /1KB) -gt 900 }

I want to pipe the results in a Copy-Item command in order to copy the results in the folder desktop\images and add to each file the .jpg extension (they don't have extensions in the source).

Can someone help, please?


Solution

  • Simply append the new extension to the name:

    ... | Copy-Item -Destination { Join-Path 'desktop\images' ($_.Name + '.jpg') }