PowerShell Quetion.

yugpatel

Senior member
Feb 28, 2001
506
0
76
I am trying to copy all .pdf files from all folders and sub folder (dirs. and subdirs).
First I used

$source = "c:\Folder1\"
$desti = "D:\foderA\"
PS> Get-ChildItem -recurse $source -Filter "*.pdf"

It displays all the files for dir and sub dir but when I try to use copy-Item I get error.

PS> Get-ChildItem -recurse $source -Filter "*.pdf" | % {Copy-Item $_ -destination $desti}
Error: Copy-Item : Cannot find path 'H:\Folder1\Folder2\..\.. because it does not exist

What am I doing wrong?
 
Last edited:

HitAnyKey

Senior member
Oct 4, 2013
648
13
81
Your pipeline input is missing the property fullname... rest of your code is fine...

Get-ChildItem -recurse $source -Filter "*.pdf" | % {Copy-Item $_.fullname -destination $desti}