l--*_*''' 3 windows powershell
我将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"
}
}
Run Code Online (Sandbox Code Playgroud)
我认为这将复制目标上不存在的文件.但是,我还想复制存在但文件大小不同的文件.
Ans*_*ers 10
使用robocopy而不是尝试在PowerShell中重新创建它.
robocopy D:\Test1 D:\Test2 /s
Run Code Online (Sandbox Code Playgroud)
如果您还想包含只有属性不同的文件("调整文件"),也可以添加/it.