Click here to Skip to main content
15,881,588 members
Articles / Programming Languages / C#
Article

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

Rate me:
Please Sign up or sign in to vote.
2.78/5 (13 votes)
27 Jan 2008CPOL1 min read 65.8K   3.4K   40   5
This tool is for the tester and developer to track any file system activity to a particular folder

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.

Image 1

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:

C#
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)


Written By
Software Developer HCL Technology
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 5 Pin
Vijaysubs17-Dec-12 3:09
Vijaysubs17-Dec-12 3:09 
GeneralHelp me please Pin
tranquocvietdanang2-Aug-10 22:00
tranquocvietdanang2-Aug-10 22:00 
GeneralThanks Pin
Nitin S23-Sep-09 5:11
professionalNitin S23-Sep-09 5:11 
GeneralGreat and thorough job Pin
psi_u16-Oct-08 9:25
psi_u16-Oct-08 9:25 
next step: using with network..
GeneralNice Pin
bartd2-Apr-08 7:19
bartd2-Apr-08 7:19 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.