2

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?

4
  • I've used Karen's Replicator in the past and it's been very good: karenware.com/powertools/ptreplicator.asp
    – nickf
    Jun 23, 2010 at 21:56
  • 1
    This belongs on superuser.com Jun 23, 2010 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, 2010 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. Oct 15, 2016 at 19:11

6 Answers 6

9

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

4
  • Oooh.. how did I not know about this?
    – mpbloch
    Jun 23, 2010 at 22:09
  • 4
    I use robocopy /mir source dest quite a lot Jun 23, 2010 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, 2010 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, 2014 at 12:39
0

Total Commander has a synchronization function.

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".

2
  • wait.. this is silly, editing..
    – mpbloch
    Jun 23, 2010 at 22:05
  • i'm pretty much doing that now but it's really slow.
    – milkplus
    Jun 23, 2010 at 22:10
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
2
  • /MT:1 option only available in Win7 and up. Mar 29, 2018 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. Mar 29, 2018 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.

You must log in to answer this question.