Monitor file changes in folders

Source: Internet
Author: User

monitor file changes in folders

Using system; using system. io; namespace consoleapplication1 {class program {static void main (string [] ARGs) {Watch ();} static datetime now = datetime. now; static string filename = string. empty; Private Static void Watch () {filesystemwatcher mywatcher = new filesystemwatcher ("E: \ drivers"); mywatcher. filter = "*. * "; mywatcher. enableraisingevents = true; mywatcher. changed + = new filesystemeventhan Dler (mywatcher_changed); mywatcher. created + = new filesystemeventhandler (mywatcher_created); mywatcher. deleted + = new filesystemeventhandler (mywatcher_deleted); mywatcher. renamed + = new renamedeventhandler (mywatcher_renamed); console. read ();} static void mywatcher_renamed (Object sender, renamedeventargs e) {If (datetime. now-Now ). totalmilliseconds> 100 | filename! = E. name) {console. writeline (string. format ("{0} -- rename -- {1}", E. oldname, E. name); filename = E. name; now = datetime. now ;}} static void mywatcher_deleted (Object sender, filesystemeventargs e) {If (datetime. now-Now ). totalmilliseconds> 100 | filename! = E. name) {console. writeline ("delete"); filename = E. name; now = datetime. now ;}} static void mywatcher_created (Object sender, filesystemeventargs e) {If (datetime. now-Now ). totalmilliseconds> 100 | filename! = E. name) {console. writeline ("CREATE"); filename = E. name; now = datetime. now ;}} static void mywatcher_changed (Object sender, filesystemeventargs e) {If (datetime. now-Now ). totalmilliseconds> 100 | filename! = E. Name) {console. writeline ("content changed"); filename = E. Name; now = datetime. Now ;}}}}

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.