olidev
olidev

Reputation: 20674

FileSystemWatcher with specifying a datetime?

I want to specify the FileSystemWatcher to check the files in the system has changed since a datetime:

FileSystemWatcher watcher = new FileSystemWatcher();

watcher.Path = @"C:\MyDirectory";
watcher.Changed+= new RenamedEventHandler(watcher_Changed)
watcher.EnableRaisingEvents = true;

How can I specify it such that: when the watcher is started, there are already existing files inside the folder. The fileSystemWatcher will get notified for the files are after a specific date time. how is it implemented with FileSystemWatcher? or if not, what is other alternatives?

Thanks in advance.

Upvotes: 0

Views: 682

Answers (2)

olidev
olidev

Reputation: 20674

I found it:

before watching a folder using watcher.Notify, I have to check all of the files inside a folder if they are new then process them first.

Upvotes: 0

MethodMan
MethodMan

Reputation: 18863

here is a snippet of what you can try .. you can also look at the link here as well MSDN for Code Examples FileWatcher MSDN Documentation and Example

watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite 
           | NotifyFilters.FileName | NotifyFilters.DirectoryName;
        // Only watch text files.
        watcher.Filter = "*.txt";

        // Add event handlers.
        watcher.Changed += new FileSystemEventHandler(OnChanged);
        watcher.Created += new FileSystemEventHandler(OnChanged);
        watcher.Deleted += new FileSystemEventHandler(OnChanged);
        watcher.Renamed += new RenamedEventHandler(OnRenamed);

        // Begin watching.
        watcher.EnableRaisingEvents = true;

Upvotes: 1

Related Questions