1

I'm trying to find a fast way to recursively update a folder and all subfolders from another folder. Obviously, a full delete and Xcopy would work but that is very slow.

After the update, the destination folder should exactly match the source folder. Changed files and new files should be copied.

If it makes it easier, don't worry about deleting files that are in the destination folder but missing in the source folder.

This deploy/mirror/update operation seems pretty basic. Do I really need to write a C# script to accomplish it?

  • I've used Karen's Replicator in the past and it's been very good: http://www.karenware.com/powertools/ptreplicator.asp – nickf Jun 23 '10 at 21:56
  • 1
    This belongs on superuser.com – Jason R. Coombs Jun 23 '10 at 22:02
  • Unless you are using C# libraries which manipulate the NTFS file system directly, you are not going to see any performance gain over calling a process for a program which manipulates files, such as those mentioned thusfar. – mpbloch Jun 23 '10 at 22:11
  • This is quite simple to do from .net. You compare src and destination by checking date stamps and file length. Copy what has changed only, remove what no longer exists. – TheLegendaryCopyCoder Oct 15 '16 at 19:11

6 Answers6

8

RoboCopy is a command line tool provided by Microsoft that can do mirroring. The Wiki page also mentions a GUI.

chilltemp
  • 231
  • 2
  • 4
  • Oooh.. how did I not know about this? – mpbloch Jun 23 '10 at 22:09
  • 3
    I use `robocopy /mir source dest` quite a lot – the_mandrill Jun 23 '10 at 22:12
  • 1
    Robocopy does work quite well, except for changes to permissions. If the only change is to permissions, that would not be picked up as a change and re-copied. To ensure that permissions are mirrored, there would need to be a second permissions-only copy with the COPY:SOU switch. – Greg Askew Jun 24 '10 at 11:20
  • Robocopy tip: add `/DCOPY:T` if you want to folder timestamp to stay the same. Otherwise it will be the current timestamp. – Peet Brits Sep 29 '14 at 12:39
0

Total Commander has a synchronization function.

Deniz Dogan
  • 143
  • 3
0

If you're happy with doing it from the CLI, xcopy (built into WinXP) and robocopy (built into Vista/Win7) both do "only if newer" copies.

0

Given a folder "source" and "dest", where you want "dest" to match "source".

  1. xcopy /e /d source dest

Saw your comment "dont worry about deleting outdated files".

mpbloch
  • 962
  • 8
  • 14
0
    cls
    @echo off
    pushd %~dp0 >nul 2>&1
    if not "%1" == "max" start /max cmd /c %0 max & exit/b >nul 2>&1
    color 1f
    TITLE robocopy "Source" "Dest" /FFT /NC /NDL /MIR /IT /MT:1 /R:0 /W:0
    robocopy "Source" "Dest" /FFT /NC /NDL /MIR /IT /MT:1 /R:0 /W:0
    exit /b n
  • /MT:1 option only available in Win7 and up. – Rick Fithen Mar 29 '18 at 19:40
  • 1
    please add some context to your answer, posting code alone is not enough. Some small comments will suffice. Also your comment about Win7 belongs to the answer itself, not the comment area. – Luca Gibelli Mar 29 '18 at 23:12
-1

I would probably do this with some version control system, probably git. Just create a repo in the source and destination directories. To sync, just commit from the source directory and checkout from the destination directory.

Git is very, very fast. I've heard that Mercurial is also (though I don't know from experience).

This approach will also give you lots of flexibility if you need to do more later.

kerkeslager
  • 179
  • 1
  • 3