-3

FileSystemWatcher C#

Folder Structure C:\A\B\C\D\E\F\abc.txt

Delete a nested folder B fires only one event for the root folder B

But Shift + Delete fires the events for all sub folders and files.

I need to get Delete nested folder events same as Shift + Delete

The below question is similar to my requirement, but it's not working

C# FileSystemWatcher.Deleted not Firing on "normal" deleting?

Community
  • 1
  • 1
Ullan
  • 1,311
  • 8
  • 21
  • 34
  • Why does monitoring renames not work? What happens? – CodesInChaos Mar 09 '12 at 17:06
  • No its not working if I delete – Ullan Mar 09 '12 at 17:08
  • @HPFE455 - [You've already been told](http://stackoverflow.com/questions/9628011/how-to-get-the-deleted-file-folders-using-filesystemwatcher/9628059#comment12219986_9628059) there is not a single event that works for both cases. Why ask the question again? – M.Babcock Mar 09 '12 at 17:10
  • Babcock, my previous question was not clear, I cant delete that question, I was asking about the recyle bin also, I thougt that question was a confusing one. I found similar question above that mentioned. I need a solution very badly. I am sorry.. – Ullan Mar 09 '12 at 17:13
  • possible duplicate of [C# FileSystemWatcher.Deleted not Firing on "normal" deleting?](http://stackoverflow.com/questions/8048031/c-sharp-filesystemwatcher-deleted-not-firing-on-normal-deleting) – Jon B Mar 09 '12 at 17:35

1 Answers1

2

The below question is similar to my requirement, but it's not working

Define "not working". As mentioned in the accepted answer for question that you referenced, the default behavior in Windows is that when you press the delete key, the file is not actually deleted- it is moved to a special folder called the recycle bin.

If you handle the renamed and changed events, you should see evidence of the moves to the recycle bin, but as you found the events will probably be raised only for the parent folder (see also Detecting moved files using FileSystemWatcher). There is probably no way to get the events for the child folders/files. If you need to keep track of the children, you'll need to index them into some data structure before they get deleted.

Also, keep in mind that some people (like me) disable the recycle bin altogether, and for us a delete is a delete.

Community
  • 1
  • 1
Chris Shain
  • 50,833
  • 6
  • 93
  • 125
  • I think this is the way I can resolve the issue. Maintain a list of files in the watch directory, while deleting, use the list values and deleted folder path and manipulate based on my requirement. – Ullan Mar 09 '12 at 17:19
  • That sounds right to me. Beware the other thing I mention, where the recycle bin is disabled altogether. – Chris Shain Mar 09 '12 at 17:21
  • 1
    @HPFE455 - Do you mean something like what was [suggested to you](http://stackoverflow.com/a/9628059/635634) 15 hours ago? – M.Babcock Mar 09 '12 at 17:21
  • 1
    @M.Babcock sorry I didn't see your answer over there- didn't mean to snipe the question. Gave you a +1 FWIW. – Chris Shain Mar 09 '12 at 17:24
  • Babcock, I accpted your comment as a solution. I am trying to implement that. thanks for understanding the functionality. – Ullan Mar 09 '12 at 17:24
  • @ChrisShain - Not your fault (and I appreciate the upvote)... your answer is clearer than mine anyway. +1 – M.Babcock Mar 09 '12 at 17:25