Access file before it's deleted Access file before it's deleted windows windows

Access file before it's deleted


Is it possible to access a file before it's deleted when using FileSystemWatcher.OnDeleted event?

The event is triggered after the file deletion not before, so you won't be able to access the file when this event is raised.

Any Ideas how to accomplish this if it's even possible ?

I would use the OnChanged event instead, which is fired every time the file changes. Basically, you read the file metadata every time the file changes. This can be a bit cumbersome if the file gets updated very often but should allow you to have the latest metadata before the file is removed.


FileSystemWatcher1 = Your Main Watcher.FileSystemWatcher2 = RecycleBin WatcherIf the FileSystemWatcher1 Deleted file == the FileSystemWatcher2 Created File{    //Do what you want with the FileSystemWatcher2.FullPath}