How to compare two folders and replace the newer versions of files with the older one.
How to compare two folders and replace the newer versions of files with the older one.
I know this is a weird use case, hence I haven't found any app that does this but maybe there is and I just don't know it...
or perhaps it can be done with a batch script?
or perhaps it can be done with a batch script?
Re: How to compare two folders and replace the newer versions of files with the older one.
Untested myself but from what I've read https://ss64.com/nt/robocopy.html (standard on Windows as far as I know, at least since a few years) will skip identical files (size, time, date) but copy files that have different timestamps - so if your source folder has older files, it should overwrite those in the target folder. A quick test should show you if it works and if so you can save it as a batch file.
- Andrew Lee
- Posts: 3070
- Joined: Sat Feb 04, 2006 9:19 am
- Contact:
Re: How to compare two folders and replace the newer versions of files with the older one.
Was going to suggest robocopy as well, or something like DSynchronize if you prefer a GUI.
Re: How to compare two folders and replace the newer versions of files with the older one.
If a probably faster(?) CLI utility interests you, then maybe the older XCOPY command (also a CMD default) will do your bidding... its 'MAXAGE' and 'MINAGE' parameters work with file timestamps.lintalist wrote: ↑I've read https://ss64.com/nt/robocopy.html (standard on Windows as far as I know, at least since a few years)...
Re: How to compare two folders and replace the newer versions of files with the older one.
Thank you all for all the advices.
Tried DSynchronize but it doesn't have an option to replace newer files with older files.
Oj don't want to replace older files with newer files, but the opposite, so that if I have two files, the older one replaces the newer file.
I apologize should had better explained this before.
And thanks for robocoy &xcopy will give them a try..
Tried DSynchronize but it doesn't have an option to replace newer files with older files.
Oj don't want to replace older files with newer files, but the opposite, so that if I have two files, the older one replaces the newer file.
I apologize should had better explained this before.
And thanks for robocoy &xcopy will give them a try..
Re: How to compare two folders and replace the newer versions of files with the older one.
None of them seem to support it
Re: How to compare two folders and replace the newer versions of files with the older one.
I just tested it and RoboCopy simply copies the older file from source to target, I just did:
output - note it copied one "older" file (file1.txt)
Code: Select all
Robocopy.exe source\ target\
Code: Select all
-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows
-------------------------------------------------------------------------------
Source : C:\tmp\source\
Dest : C:\tmp\target\
Files : *.*
Options : *.* /DCOPY:DA /COPY:DAT /R:1000000 /W:30
------------------------------------------------------------------------------
2 C:\tmp\source\
100% Older 31744 file1.txt
------------------------------------------------------------------------------
Total Copied Skipped Mismatch FAILED Extras
Dirs : 1 0 1 0 0 0
Files : 2 1 1 0 0 0
Bytes : 62.0 k 31.0 k 31.0 k 0 0 0
Times : 0:00:00 0:00:00 0:00:00 0:00:00
Re: How to compare two folders and replace the newer versions of files with the older one.
with older files from the target and soource folders? because otherwise a regular operation would do.
i.e I have:
folder 1
file1 2022
file2 2019
folder 2
file1 2019
file2 2022
I need to end up with
file1 2019
file2 2019
i.e I have:
folder 1
file1 2022
file2 2019
folder 2
file1 2019
file2 2022
I need to end up with
file1 2019
file2 2019
Re: How to compare two folders and replace the newer versions of files with the older one.
Try with /xn
seems to work here with the files setup as you've described them
Code: Select all
Robocopy.exe /xn source\ target\