我正在将 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"
}
}
我认为这将复制目的地不存在的文件。但是,我也想复制确实存在但大小不同的文件。
最佳答案
使用robocopy
而不是尝试在 PowerShell 中重新发明它。
robocopy D:\Test1 D:\Test2 /s
如果您还想包含只有属性不同的文件(“调整后的文件”),请同时添加 /it
。
关于windows - 如何复制整个目录结构?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15562443/