|
-
April 25th, 2009, 04:42 PM
#1
Read the content of a file before it is being changed
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
-
April 25th, 2009, 05:04 PM
#2
Re: Read the content of a file before it is being changed
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....
Last edited by nelo; April 25th, 2009 at 05:05 PM.
Reason: I need to correct a grammatical error...:)
-
April 25th, 2009, 05:31 PM
#3
Re: Read the content of a file before it is being changed
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
-
April 25th, 2009, 05:40 PM
#4
Re: Read the content of a file before it is being changed
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.
-
April 26th, 2009, 04:32 AM
#5
Re: Read the content of a file before it is being changed
Hi,
Basically, you're right.
I would still like to see if there's any other solution to the problem.
Thanks.
-
April 26th, 2009, 12:00 PM
#6
Re: Read the content of a file before it is being changed
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.
www.monotorrent.com For all your .NET bittorrent needs
NOTE: My code snippets are just snippets. They demonstrate an idea which can be adapted by you to solve your problem. They are not 100% complete and fully functional solutions equipped with error handling.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|