WatchDirectory home page
WatchDirectory Startseite (Deutsche Version)
Site WatchDirectory (Français)
  Welcome, Guest. Please Login or Register
YaBB - Yet another Bulletin Board
   
  HomeHelpSearchLoginRegister  
 
Page Index Toggle Pages: 1
HowTo... Synchronize 2 folders (Read 6632 times)
Gert
YaBB Administrator
*****
Offline



Posts: 2232
The Netherlands
HowTo... Synchronize 2 folders
Jun 12th, 2003 at 3:47am
 
Synchronizing 2 folders with WD is easy... Ok, you will have to write a working bat-file, and know what commandline to use...
Lucky for you: I already did it (several times)!

You should use the following commandline:
Code:
watchDirectory /s /d /xO /f C:\SourceDir C:\Bin\batfile.bat
 


Explanation:
 /s                         -  Also watch subdirectories
 /d                        - Also fire DIRNEW and DIRDEL events
 /xO                       - Do not fire DIRCHNG events
 /f                          - Use the timestamp of the file
 C:\SourceDir         - the source directory
 C:\Bin\batfile.bat  - bat-file to exec (below)
Optionally you could leave the /f switch out, but then changes to a file that do not change the size of the file would not be seen by watchDirectory.

The bat-file below can almost be used as is. You will have to change the third line to 'point to' the directory that should be a mirror of the monitored directory.
Important: The target directory must exist already!
Here is the batfile to execute:
Code:
@echo off
Rem change target directory below to your needs
SET TARGET=Z:\TARG
Rem No need to change anything below


IF NOT "%WD_RELDIR%" == "" SET TARGET=%TARGET%\%WD_RELDIR%
Rem
Rem We implement ALL events (except for DIRCHNG)
Rem
GOTO %WD_REASON%


:DIRNEW
Rem
Rem A new directory is created
Rem we create the same directory in TARGET
Rem
MD "%TARGET%\%WD_FILE_N%"
GOTO QUIT

:DIRDEL
Rem
Rem A directory is removed
Rem we also remove it in TARGET
Rem
RD /q /s "%TARGET%\%WD_FILE_N%"
GOTO QUIT

:FILEDEL
Rem
Rem remove the same file in TARGET
Rem
DEL "%TARGET\%WD_FILE_N%"
GOTO QUIT


:FILENEW
:FILECHNG
Rem
Rem Copy this file over to TARGET
Rem
Rem
COPY "%WD_FILE%" "%TARGET%"
GOTO QUIT

:QUIT
Echo bye
 


Back to top
« Last Edit: Jul 4th, 2003 at 9:12pm by Gert »  

Gert Rijs - gert (at) gdpsoftware (dot) com
Blog: http://blog-en.gdpsoftware.com/
End Alzheimer's: http://www.alz.org&&...
WWW WWW GdPSoftware  
IP Logged
 
Gert
YaBB Administrator
*****
Offline



Posts: 2232
The Netherlands
Re: HowTo... Synchronize 2 folders
Reply #1 - Jul 1st, 2003 at 4:33pm
 
Note that the HowTo above will remove (delete!!) files in the target directory when the corresponding file is removed from the source directory.
If you do not want that to happen add the following lines at the top of the bat-file (just after the @echo off line):
Code:
IF %WD_REASON% == FILEDEL GOTO QUIT
IF %WD_REASON% == DIRDEL GOTO QUIT
 


Gert
Back to top
 

Gert Rijs - gert (at) gdpsoftware (dot) com
Blog: http://blog-en.gdpsoftware.com/
End Alzheimer's: http://www.alz.org&&...
WWW WWW GdPSoftware  
IP Logged
 
dcohn
YaBB Newbies
*
Offline



Posts: 3
Re: HowTo... Synchronize 2 folders
Reply #2 - Nov 25th, 2003 at 5:56am
 
I am a bit confused here.

A few questions.

The commandline you specify. Where does it show how often the directory will be polled?

Can I use UNC paths in my batch file.

Can the batch file be a CMD or a BTM or must it be a .BAT file?

Thanks

Doug
Back to top
 
 
IP Logged
 
dcohn
YaBB Newbies
*
Offline



Posts: 3
Re: HowTo... Synchronize 2 folders
Reply #3 - Nov 25th, 2003 at 7:02am
 
I got many answers from watchdirectory -help but can you explain the ones below for me.

Usage:
watchDirectory [/s] [/4] [/p[99]] [/r] [/c] [/   (continued)  [/l<file>] [/d] [/x[o][n][d][c

   /4       NT4 compatibility fix

What does this do??
   
   /r       Run in "Service Friendly" mode.
           You will need SrvAny.exe (NT resou
           FireDaemon (http://www.firedaemon.
What is the reason to run this as a service if it is a command line program???  Or is this the Monitor???

   /c       Do NOT wait for new and changed fi
           before calling bat-file

Why would you run the batch file before there are changes?
     /w       Do NOT wait for bat-files to 'clos

What does this mean do not wait to close.  What will happen?
Back to top
 
 
IP Logged
 
Gert
YaBB Administrator
*****
Offline



Posts: 2232
The Netherlands
Re: HowTo... Synchronize 2 folders
Reply #4 - Nov 25th, 2003 at 7:24am
 
mmmm, a lot of questions...
hope I won' miss one.

Quote:
Where does it show how often the directory will be polled?

Directories are polled when you select the "Poll directory for changes" option on the GUI (watchDirectoryStart).
Checking that option causes watchDirectory to be called with the /p switch. The "every xxx seconds" is passed directly after that (/p600  -- poll directory every 600 seconds).

If the /pxxx option is not present, watchDirectory will use native windows functions instead. WD will ask Windows to 'notify' it when the directory has changed.
So...
If at all possible, do not select "poll directory for changes".
It is far more efficient when WD is notified by windows. However, some network drives (actually, network software) do not implement these notifications, so then you must use the polling method.


Quote:
Can I use UNC paths in my batch file.

Yes, but....
You can monitor UNC paths (\\server\share) with watchDirectory, but not in the free edition.
What you do in your .bat file is totally up to you. However, one thing to keep in mind: if you run watchDirectory as a Windows Service application, the .bat file runs (by default) as LocalSystem user. That user does not have any rights on network drives.
Please read http://www.gdps.dk/products/watchDir/help/fire.html for some extra info.

Quote:
Can the batch file be a CMD or a BTM or must it be a .BAT file?


Tested with .bat and .cmd
BTM?? is that 4Dos??

Gert
Back to top
 

Gert Rijs - gert (at) gdpsoftware (dot) com
Blog: http://blog-en.gdpsoftware.com/
End Alzheimer's: http://www.alz.org&&...
WWW WWW GdPSoftware  
IP Logged
 
Gert
YaBB Administrator
*****
Offline



Posts: 2232
The Netherlands
Re: HowTo... Synchronize 2 folders
Reply #5 - Nov 25th, 2003 at 7:57am
 
Quote:
/4  NT4 compatibility fix
What does this do??

One of our customers had a problem on Windows NT 4.x (very strange, on our NT4 system all was ok).

The effect of the /4 switch is that your .bat file will receive only 1 parameter from watchDirectory: the event name (FILENEW, FILEDEL etc). If I remember correctly, on some NT4 systems the other parameters that are normally passed to the .bat file caused problems (.bat file not started).

If you select the /4 switch you still have all information about the event available in environment variables (%WD_FILE% etc).

Working with environment variables is, in my opinion, much more conveniant then command line options.

Quote:
   
  /r  Run in "Service Friendly" mode.

watchDirectory is a command line program, however some people prefer to run it as a windows service program.
If you don't want to run WD as a service application, just ignore the switch. If you want to run WD as a Service, you must pass this switch ("Service friendly" option on the GUI") to watchDirectory. This switch causes WD to ignore the Windows user logging off (otherwise WD will exit when the user exits windows).
We are currently working on a major redesign of WD (free upgrade for current owners), and, among other things, WD will be able to run as a Service application without 3rd party tools.

Quote:
  /c  Do NOT wait for new and changed files
Why would you run the batch file before there are changes?

/c -- "Don't wait for files to be available" on the GUI
The point here is that WD receives a notification from Windows when a change is detected. This notification is received when the first bit of the file is changed. It can very well be that the changes are not ready yet.

Suppose the following scenario:
WD watches C:\Temp
You compress (WinZip) the file hello.txt in that directory
A microsecond after you started the compress, windows notifies WD that hello.zip is created/changed.

The /c option controls if your .bat file is called:
- when you start zipping (/c option on the command line)
- when you finish zipping (/c option not on the command line)

Quote:

/w  Do NOT wait for bat-files to 'clos
What does this mean do not wait to close.  What will happen?

/w -- "Don't wait for bat files to exit" on the GUI
Easy (ok, not very well explained in the documentation):

If the /w option is on the command line watchDirectory will start your .bat file as soon as a change is detected. That can cause multiple .bat files running at the same time. If you copy 10 files into the monitored directory, WD will start your .bat file 10 times, they are running at the same time.... This can cause serious problems if your .bat file needs exclusive access to a resource (a file, printer whatever) .

If the /w option is not on the command line, watchDirectory will wait until the first .bat file has finished running before it will start the .bat file for the next changed file.

Hope this is understandable,
Gert
Back to top
« Last Edit: Dec 12th, 2003 at 9:34pm by Gert »  

Gert Rijs - gert (at) gdpsoftware (dot) com
Blog: http://blog-en.gdpsoftware.com/
End Alzheimer's: http://www.alz.org&&...
WWW WWW GdPSoftware  
IP Logged
 
Page Index Toggle Pages: 1