subs
subs

Reputation: 2249

How to detect new changes in a file?

I am trying to build a logViewer which displays log from multiple files. I want to display the new changes in the files as soon as they are modified. I am using a FileSystemWatcher to detect if a file has been changed. But I am not sure how do I detect the change that has been made in the file that I am monitoring. I have seen some of the questions in StackOverflow but they are not helpful. How do I do this?

Edit: All I want is to get the line/lines that have been added. If there are any method other than using FileSystemWatcher I am fine with that also.

Upvotes: 0

Views: 1483

Answers (3)

Besides FileSystemWatcher your task can be solved (quite efficiently) using a filesystem filter driver. With such driver you'll know about the changes right when (before or after) they are made, and you know what exactly is done.

You can write a filter yourself if you have experience with kernel-mode development or use our CallbackFilter product, though the latter is an overkill for your needs.

Upvotes: 0

Faisal
Faisal

Reputation: 364

Use the filesystemwatcher to detect changes and get new lines using last read position and seek the file.

https://stackoverflow.com/a/19230599/1583653

Upvotes: 2

Pseudonym
Pseudonym

Reputation: 2072

If you are looking to do this programmatically you will need to have both the previous version and the current version. Then you will have to make a comparison somehow: letter by letter, word by word, etc, and then go from there.

FileSystemWatcher only detects if the change has happened, it doesn't detect the change itself.

Upvotes: 1

Related Questions