Page 1 of 1

How to compare two folders and replace the newer versions of files with the older one.

Posted: Sat Sep 24, 2022 11:52 am
by Marc
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?

Re: How to compare two folders and replace the newer versions of files with the older one.

Posted: Sun Sep 25, 2022 2:52 am
by lintalist
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.

Re: How to compare two folders and replace the newer versions of files with the older one.

Posted: Sun Sep 25, 2022 4:51 am
by Andrew Lee
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.

Posted: Sun Sep 25, 2022 12:25 pm
by Midas
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)...
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.

https://ss64.com/nt/xcopy.html

Re: How to compare two folders and replace the newer versions of files with the older one.

Posted: Mon Sep 26, 2022 8:10 am
by Marc
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..

Re: How to compare two folders and replace the newer versions of files with the older one.

Posted: Wed Sep 28, 2022 6:34 pm
by Marc
None of them seem to support it :(

Re: How to compare two folders and replace the newer versions of files with the older one.

Posted: Wed Sep 28, 2022 11:32 pm
by lintalist
I just tested it and RoboCopy simply copies the older file from source to target, I just did:

Code: Select all

Robocopy.exe source\ target\
output - note it copied one "older" file (file1.txt)

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.

Posted: Thu Sep 29, 2022 1:28 pm
by Marc
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

Re: How to compare two folders and replace the newer versions of files with the older one.

Posted: Fri Sep 30, 2022 1:20 am
by lintalist
Try with /xn

Code: Select all

Robocopy.exe /xn source\ target\
seems to work here with the files setup as you've described them

Re: How to compare two folders and replace the newer versions of files with the older one.

Posted: Thu Oct 06, 2022 8:09 pm
by Marc
Thank you!! =)