actively monitor a computer for when a new file has been created, an existing file has been edited, or a file has been deleted?

AndrewBanfer
AndrewBanfer used Ask the Experts™
on
Is there a way in VB.Net to actively monitor a computer for when a new file has been created, an existing file has been edited, or a file has been deleted?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
Yes, absolutely. That's the entire purpose of the FileSystemWatcher class in the .NET framework:
https://docs.microsoft.com/en-us/dotnet/api/system.io.filesystemwatcher

Basically, you create a new instance of the watcher, set up the filters so you're only notified about events you care about, and then you subscribe to events so your code can respond when one of those events (file creation, update, delete) happens.

That said, just bear in mind that SOME programs have some weird ways of interacting with files. For example, you might think you're looking for a file update event, but it turns out that a program deletes the old file and writes a full new one, which would generate delete and create events instead of an update event.

Ultimately, the file system watcher is just paying attention to what the file system is doing. If a program has some weird way of updating a file or something like that, then it's up to you to understand the pattern and figure out how to interpret the events with your code.
John TsioumprisSoftware & Systems Engineer
Commented:
Beyond the builtin FileSystemWatcher there are cases that might not work..especially if you have a mixed Environment.
In that case you need a simple Timer control that will scan the folder/s for changes in predefined intervals (e.g. 5 minutes) and action back...in that case you will a database BE to hold the information to check against...
File Hashing will give you the info if a file has changes while the existense/not would be checked against the database i mentioned.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial