Click here to Skip to main content
Click here to Skip to main content

Folder Listener: A Tool to Watch File System Activity in any Folder

By , 27 Jan 2008
 

Introduction

Most of the time when you are doing some development or testing, you might need to know what changes are made in a particular folder. This requirement frequently arises when you are testing /developing software that copies /delete files in the background without user intervention; for example background update and installation/un-installation of software product. It can also be useful when you want to know the intermediate file that a particular application creates in a particular folder.

Technology Used

This application is based on Microsoft's .NET Framework 2.0 and is written in C#. .NET Framework provides a component FileSystemWatcher that is used to track and listen to the changes made in a particular folder. You may find several articles on this component, so I am not going to explain the working code. Below is the code segment that allows you to create a FileSystemWatcher.

Using the Code

It uses the FileSystemWatcher component of the .NET Framework. The main code snippet is given below:

FileSystemWatcher fsw = new FileSystemWatcher();
fsw.Path = textBox1.Text;
fsw.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | 
                   NotifyFilters.DirectoryName | NotifyFilters.FileName;
fsw.Changed += new FileSystemEventHandler(OnChanged);
fsw.Created += new FileSystemEventHandler(OnCreated);
fsw.Deleted += new FileSystemEventHandler(OnChanged);
fsw.Renamed += new RenamedEventHandler(OnRenamed);
fsw.EnableRaisingEvents = true;

Tool Limitations

This tool is designed to listen to a single folder at a time. However in future, I will update it for multiple folders.

Using the Tool

Use of this tool is very simple. Just run the tool and select the folder you want to listen to or track.

History

  • 27th January, 2008: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Ashwini K Singh
Software Developer HCL Technology
India India
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 5memberVijaysubs17 Dec '12 - 3:09 
GeneralHelp me pleasemembertranquocvietdanang2 Aug '10 - 22:00 
GeneralThanksmemberNitin Sawant23 Sep '09 - 5:11 
Thanks a lot .. i'm trying your code... Big Grin | :-D
 
=============
NITIN SAWANT
=============

GeneralGreat and thorough jobmemberpsi_u16 Oct '08 - 9:25 
GeneralNicememberbartd2 Apr '08 - 7:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130523.1 | Last Updated 27 Jan 2008
Article Copyright 2008 by Ashwini K Singh
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid