Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access file before it's deleted

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

I'm storing some data about the document itself in its metadata and i need that info before it's deleted.

Any Ideas how to accomplish this with or without FileSystemWatcher if it's even possible ?

Update ://

I realized that storing the data in the file is bad as i cannot access it when file is deleted.

Solution : rewrite my app to store the data in a local database(sqlite/xml or something like that) as i get the full path and name when the file is being created/renamed/updated/deleted it would be easier to update the database record for the file.

Thanks to all for the ideas and suggestions!

like image 758
Nikola Sivkov Avatar asked May 04 '12 22:05

Nikola Sivkov


1 Answers

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.

like image 166
GETah Avatar answered Oct 16 '22 15:10

GETah