In order to monitor the static file of the Web program is malicious change, so learned the FileSystemWatcher class to the file monitoring, because still in the initial stage, here only a few about FileSystemWatcher learning code.
The specific code is as follows:
#using<System.dll>#include<iostream>using namespacestd;using namespaceSystem;using namespaceSystem::IO;using namespacesystem::security::P ermissions; Public ref classwatcher{Private: //Define the event handlers. Static voidOnChanged (object^/*Source*/, filesystemeventargs^e) {//Specify what was done when a file was changed, created, or deleted.Console::WriteLine ("File: {0} {1}", E->fullpath, e->changetype); } Static voidOnrenamed (object^/*Source*/, renamedeventargs^e) {//Specify what was done when a file was renamed.Console::WriteLine ("File: {0} renamed to {1}", E->oldfullpath, e->FullPath); } Public: [PermissionSet (SecurityAction::D emand, Name="FullTrust")] int Staticrun () {//Array<string^>^args = System::environment::getcommandlineargs (); //creates a FileSystemWatcher and sets its properties.filesystemwatcher^ Fswatcher =gcnew FileSystemWatcher (); Fswatcher->path ="C:\\files"; /*Watch for changes in Lastaccess and lastwrite times, and the renaming of files or directories.*/Fswatcher->notifyfilter = static_cast<notifyfilters> (//the following properties of the listener file are added as required here I have added some commonnotifyfilters::lastaccess |//the date on which the file or folder was last opened. Notifyfilters::lastwrite |//The last date the content was written to a file or folderNotifyfilters::filename |//file nameNotifyfilters::D irectoryname |//Directory nameNotifyfilters::size);//size//Listen to subdirectoriesFswatcher->includesubdirectories =true; //Only watch text files. //fswatcher->filter = "*.txt"; //ADD event handlers.Fswatcher->changed + =gcnew FileSystemEventHandler (watcher::onchanged); Fswatcher->created + =gcnew FileSystemEventHandler (watcher::onchanged); Fswatcher->deleted + =gcnew FileSystemEventHandler (watcher::onchanged); Fswatcher->renamed + =gcnew Renamedeventhandler (watcher::onrenamed); //Begin watching.Fswatcher->enableraisingevents =true; //Wait for the user to quit the program.Console::WriteLine ("Press \ ' q\ ' to quit the sample." ); while(Console::read ()! ='Q' ); return 0; }};intMain () {Watcher::run ();}
Procedure 1. First create a FileSystemWatcher object to set some properties and add listener events
2. Setting the Listening directory
3. Setting the properties of a listening file
4. Setting up a listener subdirectory
5. Adding a listener Event
6. Start monitoring
The sample code above can be found on MSDN, and if you have an indeterminate place, you can view the document
FileSystemWatcher of file Monitoring (C + +)