这个问题在这里已经有了答案:
How to copy certain files (w/o folder hierarchy), but do not overwrite existing files?
(5 个回答)
6年前关闭。
Total N00b 到 Powershell 并且已经有一个脚本,该脚本使用 Robocopy 将文件及其目录结构复制到另一个文件夹,然后将它们从子文件夹复制到根文件夹。是的,我试过搜索,但找不到任何有用的东西。
这是第二步的 Powershell 命令:get-childitem -rec -include *.* | copy-item -destination 'yourpath'
有什么我可以添加的,以便它不会复制目标目录中已经存在的文件(根据文件名),即文件夹结构的根目录?
提前致谢
最佳答案
一种选择是将 get-childitem 的输出通过管道传输到 Test-Path cmdlet 以检查目标文件是否存在:
get-childitem -rec -include *.* | ? { !(Test-Path "yourpath\$($_.Name)") } | copy-item -destination 'yourpath'
关于file - Powershell 将文件从多个子文件夹复制到单个文件夹,忽略重复项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30033255/