Link to home
Start Free TrialLog in
Avatar of Jay Toops
Jay ToopsFlag for United States of America

asked on

I need to create a function in VB.NET to synchronize 2 directories w/recursion

Hi ..

I need a vb.net function to recursively synchronize 2 directories.
anybody have anything that would be helpfull?

i basically want to replace synchronization windows has because it stinks ...

and don't have the time necessary to really look at it all myself .. and this would help a lot..

Jay
Avatar of Alexandre Simões
Alexandre Simões
Flag of Switzerland image

Questions...
- Do you have updated files on the source dir?
- Dows the source dir have nested directories also to be synchronized?

You have 2 options:
1. Iterate thru the files and folders on the source dir evaluating if the file exists on the destination dir and if the Last Modified date is the same or not.
2. Use a System.IO.FileSystemWatcher, enabling the IncludeSubdirectories property.

Remarks:
On option 1 you need to specify the time interval to run the process... maybe on a Timer.
On option 2 the files will be synchronized automatically upon creation or modification, just handle the Events of the FileSystemWatcher.

This is certainly a good solution for a windows service, specially if this is to run on a server that may not always be logged.

Alex :p
Avatar of Jay Toops

ASKER

Q1) updates on source and target
Q2) there are nested directiories hence, recursion

Option 1) is preferrable
time to run will be ON LOGIN /  ON LOGOFF
and ON USER REQUEST

example:
Synchronize
C:\Documents and Settings\jay\My Documents
with
\\filesvr\home directories\jay

and
c:\groupshare
with
\\filesvr\groupshare

ASKER CERTIFIED SOLUTION
Avatar of Alexandre Simões
Alexandre Simões
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
hey this looks good....
i'll test it an get back to you ... probably tomorrow

Jay
I really didn't tested it... nothing...
Try it on a simple scenario first and step by step debug it ok?

See ya...

Alex :p
oh be sure i will do that ... I wasn't born yesterday ... LOL ..

Jay
This works quite well,
Thanks...

Jay
Glad to know...

Alex :p