Click to See Complete Forum and Search --> : Read the content of a file before it is being changed
Trinominal
April 25th, 2009, 04:42 PM
Hi,
I'm monitoring a directory to see if there are any changes in its content. If a certain file in this directory is being changed, or overriden, I want to be able to read its content before it have been changed with the new content.
Naturally, I tried using FileSystemWatcher class, but it allerts me that the file changed after it have changed, and the old content is already gone.
Can someone point me to a solution, proferrably another C# class which provide the functionality I'm looking for?
Thanks
nelo
April 25th, 2009, 05:04 PM
Hi,
Why can't you keep a copy of the file at beginning of the monitoring process? Then each time it changes you'll be notified. When you receive the notification make another copy of the file. That way each time the file changes you can always look at the content of the previous version as you have a copy of it. Alternatively, you can just read the contents and store them instead of copying the file....
Trinominal
April 25th, 2009, 05:31 PM
Hi,
Thanks for the reply.
Saving a copy is not good enough when you're dealing with large scale directories, and don't want the first copy of all the files to take 10 or more minutes.
Any other solutions?
Thanks
nelo
April 25th, 2009, 05:40 PM
Hi,
Does it really matter how long it takes? The first will only need to happen once per file for the duration of the application. 10 minutes doesn't sound like a lot in terms of setup/initialisation time.
Trinominal
April 26th, 2009, 04:32 AM
Hi,
Basically, you're right.
I would still like to see if there's any other solution to the problem.
Thanks.
Mutant_Fruit
April 26th, 2009, 12:00 PM
This would require explicit support by the filesystem, which isn't there. Therefore there's no easy way to do this. The easiest way to accomplish what you want would be to duplicate all the files/directories that you were monitoring and then just compare those versions to the changed versions when the file changes.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.