为什么
gci $from -Recurse | copy-item -Destination $to -Recurse -Force -Container行为方式不同于
copy-item $from $to -Recurse -Force我认为它应该是一样的,但不知何故,它不是。为什么?
发布于 2014-02-13 19:33:33
您不会循环遍历文件/文件夹集合中的每一项,而是将最后一个值传递给管道。您需要使用Foreach-item或%来执行Copy-Item命令。从那时起,您也不需要第二个-recurse开关,因为您已经拥有了GCI中的每一项。
试试这个:
gci $from -Recurse | % {copy-item -Path $_ -Destination $to -Force -Container }发布于 2014-11-26 07:49:19
以下是对我起作用的方法
Get-ChildItem -Path .\ -Recurse -Include *.txt | %{Join-Path -Path $_.Directory -ChildPath $_.Name } | Copy-Item -Destination $to发布于 2019-10-11 18:46:52
这对我来说很有效:
Get-ChildItem 'c:\source\' -Recurse | % {Copy-Item -Path $_.FullName -Destination 'd:\Dest\' -Force -Container }https://stackoverflow.com/questions/21750311
复制相似问题