这似乎是一个简单的操作,但是我无法弄清楚如何使Powershell将整个文件夹结构从一个位置复制到另一个位置,但排除一个文件夹(称为“连接”)及其内容。
我试过像这样组合Copy-Item和Get-ChildItem
cpi (gci folder1 -Exclude connections) folder2 -recurse
但是-recurse参数似乎覆盖了-exclude参数,并且复制了connections文件夹及其内容。没有-recurse,我要复制的文件夹的内容将被忽略。
我不确定为什么它不起作用,它在我的机器上似乎正常运行。
您总是可以通过管道连接到Copy-Item
:
Get-ChildItem folder1 | where { !(($_ -is [System.IO.DirectoryInfo]) -and ($_.Name -eq "connections")) } | Copy-Item -Destination folder2 -Recurse
这样做的好处是,您可以使PowerShell在以下情况下打印输出:
Get-ChildItem folder1 | where { !(($_ -is [System.IO.DirectoryInfo]) -and ($_.Name -eq "connections")) }
这样,您可以准确检查要复制的内容(即“ connections”文件夹丢失了吗?)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句