Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

migrated from stackoverflow.com Jun 24 '10 at 5:21

This question came from our site for professional and enthusiast programmers.

    
I've used Karen's Replicator in the past and it's been very good: 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

5 Answers 5

Total Commander has a synchronization function.

share|improve this answer

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

share|improve this answer
    
Oooh.. how did I not know about this? –  mpbloch Jun 23 '10 at 22:09
1  
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 at 12:39

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.

share|improve this answer

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

share|improve this answer
    
wait.. this is silly, editing.. –  mpbloch Jun 23 '10 at 22:05
    
i'm pretty much doing that now but it's really slow. –  milkplus Jun 23 '10 at 22:10

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.