How do I force Robocopy to overwrite files?

In general, Robocopy ignores files for which lastwrittendate and filesize are the same. How can we escape this design? I’d like to force overwriting with Robocopy.

I expected that dst\sample.txt should be written test001. But these file are recognized as the same files by Robocopy and not overwritten. The “/IS” option is not effective in this case.

New-Item src -itemType Directory
New-Item dst -itemType Directory
New-Item src\sample.txt -itemType File -Value "test001"
New-Item dst\sample.txt -itemType File -Value "test002"
Set-ItemProperty src\sample.txt -Name LastWriteTime -Value "2016/1/1 15:00:00"
Set-ItemProperty dst\sample.txt -Name LastWriteTime -Value "2016/1/1 15:00:00"

ROBOCOPY.exe src dst /COPYALL /MIR
Get-Content src\sample.txt, dst\sample.txt
> test001
> test002

ROBOCOPY.exe src dst /COPYALL /MIR /IS
Get-Content src\sample.txt, dst\sample.txt
> test001
> test002

Leave a Comment