Except for a typo where you have $docss I don't see why that would not work.
I've recoded as
copy-item $doc c:\ -whatif
to see exactly how the paths are defined for the copies and I see what you are
saying. It seems like a bug to me.
Even recoding as
$docs | % { copy-item $_ c:\ -whatif }
does not help. I don't see what default property would cause it to lose a node
in the path during the copy from the items in subfolders.
- Larry
Megaton wrote:
> I would like to copy a collection of .doc files to C:\ one by one and print
> out on screen.
>
> What I am doing is first getting a collection of doc files:
> $docs = get-childitem -recurse d: | where-object {$_.Name -like "*.doc"}
>
> then I use a foreach loop to go through these .doc files
>
> foreach ($doc in $docss)
> {
> copy-item $doc c:\
> write-host "Copied file ""$doc"" to directory: C:\"
> }
>
> but the problem is that the copy-item statement looks for files under the
> current working directory so I get lots errors. How do I get the path for
> each $doc?


