DirectoryMirror

An application that monitors a directory and maintains a copy of it
Download

DirectoryMirror Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Freeware
  • Publisher Name:
  • Luc Archambault
  • Publisher web site:
  • http://www.codeproject.com/Members/Luc-Archambault
  • Operating Systems:
  • Windows All
  • File Size:
  • 9 KB

DirectoryMirror Tags


DirectoryMirror Description

The DirectoryMirror application was developed to be a small tool that monitors a directory and maintains a copy of it. This application creates and maintains a mirror of a selected directory; it monitors IO activity in the specified directory and reacts to this in order to keep a copy of the contents (including subfolders) in another directory. This is an implementation of the System.IO.FileSystemWatcher class.I've created a class called directoryMirror which is based on the FileSystemWatcher class. The handlers for the events (changed, created, deleted, renamed) of this class do all the work of maintaining a copy of the "source" directory in a "mirror" directory. I've added an event to the class which sends messages about IO activity and various exceptions. I've also added a property called mirrorDirectory that points to a string containing the path of the mirror folder, and a second property called sourceDirectory which is nothing more than the Path property of the FileSystemWatcher class.There are eight different NotifyFilters, and as you will notice, our directoryMirror class uses three of them: the FileName, DirectoryName, and LastWrite NotifyFilters. This determines what changes to monitor. The Filter property lets you select what kind of files you want to watch. Just set the value to a file extension, for example, ".txt" for text files. Our directoryMirror class' Filter property is set to an empty value "" so we'll be monitoring all files and directories, as well as subdirectories because the IncludeSubdirectories property is set to true.It's a well known bug that file paths returned by the event arguments System.IO.FileSystemEventArgs lose their original casing and are all in lower case. This is not too bad since the operating system makes no difference in the casing of file paths.Believe it or not, I actually had a practical use for this little application when I created it! I might also say that I created the need because I had been itching to experiment with the FileSystemWatcher class for a long time. I made minor changes to my original application to make it more educational. If the uses of this application are somewhat limited, I think the code can be helpful to anybody looking for an introduction to the FileSystemWatcher class.


DirectoryMirror Related Software