我正在将 10,000 个文件从一个目录复制到另一个目录。
两个目录结构都有相同的文件;但是,尺寸可能会有所不同。
如何强制覆盖不同大小的文件而不复制相同大小的文件?
到目前为止我有这个:
$source = 'D:\Test1'
$destination = 'D:\test2'
$exclude = @('*.db','test2.log')
$sourcelist = Get-ChildItem $source -exclude $exclude
foreach ($file in $sourcelist){
$result = test-path -path "$destination\*" -include $file
if ($result -like "False"){
#uncomment the next line to see the value being passed to the $file parameter
#Write-Host $file
Copy-Item "$file" -Destination "$destination"
}
}
我认为这将复制目标上不存在的文件。但是,我还想复制确实存在但大小不同的文件。
Use robocopy http://technet.microsoft.com/en-us/library/cc733145%28v=ws.10%29.aspx而不是尝试在 PowerShell 中重新发明它。
robocopy D:\Test1 D:\Test2 /s
如果您还想包含仅属性不同的文件(“调整文件”),请添加/it
以及。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)