Simple Folder Synchronization Using XCOPY

There are many times when it is necessary to make sure that one folder stays in synch with another.  The possibilities are endless, but one that I run into a lot is the need to retry copying files to a folder because they were in use when I tried the first time.  For example, I may be deploying a new build of Smart Client software but somebody is in the application so it can not be overwritten on the network. 

In order to combat this, the solution is simple.  Just using the right switches of XCOPY can work pretty smooth.  Here is a quick way to recursively copy all files.

 

set AttribPromptSwitch=/i/f/s/e/r/h/d/y/z

That one line in a .bat file can be magic if you want to do the same things that I typically do, which is “Make this folder look like that one and don’t ask me any questions!

@echo off
time /t

REM ————————-
REM — SPECIFY DIRECTORIES —
REM ————————-
set COPYSOURCE=”C:\temp\SimpleSynch\ThisFolder”
set COPYTARGET=”\\Server\Share\ThatFolder”

del SynchFromThisToThat.logs

set AttribPromptSwitch=/i/f/s/e/r/h/d/y/z

REM ————————-
REM — COPY FILES —
REM ————————-
echo “Copying from:
ECHO %COPYSOURCE%
echo “to:
ECHO %COPYTARGET%

REM This is where the actual work is done
xcopy %COPYSOURCE%\*.* %COPYTARGET% %AttribPromptSwitch% >> SynchFromThisToThat.log

time /t

REM PAUSE

If you want more detail on what each of the switches do, here are a few good references:

http://support.microsoft.com/kb/q128756/

http://commandwindows.com/xcopy.htm

http://www.geocities.com/rick_lively/MANUALS/COMMANDS/X/XCOPY.HTM

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: