Created
July 13, 2014 15:12
-
-
Save arbaaz/1cb14acdb35083e6d937 to your computer and use it in GitHub Desktop.
C# filewatcher
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Runtime.Remoting.Messaging; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.IO; | |
namespace FileWatcher | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var folderpath = @"E:\fw"; | |
// Create a new FileSystemWatcher and set its properties. | |
var watcher = new FileSystemWatcher(folderpath); | |
/* Watch for changes in LastAccess and LastWrite times, and | |
the renaming of files or directories. */ | |
watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName; | |
// Only watch text files. | |
watcher.Filter = "*.xml"; | |
// Add event handlers. | |
watcher.Created += OnChanged; | |
// Begin watching. | |
watcher.EnableRaisingEvents = true; | |
// Wait for the user to quit the program. | |
Console.WriteLine("Press \'q\' to quit the sample."); | |
while (Console.Read() != 'q') | |
{ | |
} | |
} | |
private static void OnChanged(object source, FileSystemEventArgs e) | |
{ | |
// Specify what is done when a file is changed, created, or deleted. | |
if (e.FullPath.Contains("I035")) | |
{ //method for processing I035 file | |
Console.WriteLine("File:I035 " + e.FullPath + " " + e.ChangeType); | |
} | |
if (e.FullPath.Contains("I016")) | |
{ //methond for processing I016 file | |
Console.WriteLine("File: I016" + e.FullPath + " " + e.ChangeType); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment