tags:

views:

110

answers:

1

I created a FileSystemWatcher (as a Windows Service) to watch for plug-ins being dropped in a directory (as ZIP files) so I can automatically unzip them, set some registry keys, and install them into my application. This works fine.

I also have the FileSystemWatcher looking to see when a ZIP file is deleted, so I can delete the install, remove the registry keys, etc. This, too, works fine...except for one catch.

When I do a delete, the file is completely deleted, but it looks like another ZIP file had been added, but it has a really strange name. Also, the contents in the registry are the same as the file I just deleted. Here is an example:

Install
-------
File: Example.zip
Extracts to: C:\Plugins\Example\*.*
Registry Key: HKLM\Software\MySoftware\Plugins\Example\[keys]

Delete
------
File: Example.zip
Directory Deletes
Registry Deletes
Creation of Folder: C:\Plugins\ER\S-1-52359402-2823975235\202\*.* where the files are the same as Example.zip's files.
Registry Key: HKLM\Software\MySoftware\Plugins\ER\S-1-52359402-2823975235\202\[keys] where the keys are the same as Example.zip's.

Those last two steps should not happen. I'm really confused on what is going on here. Is this a virus scanner that is doing it? Any help would be much appreciated.

Update: Per Jon Skeet's response, it appears that it is the Recycling Bin causing this problem (I am watching subdirectories). Is there any way to consistently ignore these directories (hidden? recycling bin? something else?).

+2  A: 

Is it the recycle bin perhaps? How are you deleting the file? If you're doing it manually from Explorer, is there any difference between a "normal" highlight-and-delete and the "delete immediately" behaviour of Shift+Delete?

Jon Skeet
That does appear to be the problem. Any suggestions for how to manage this? (Updating question to match the find.)
JasCav
Does your addin architecture require you to watch all subdirectories? You could just monitor the top-level folder to avoid that problem.
0xA3
Well, based on the current design, it does require that I watch all subdirectories. I suppose I could change the design, but it makes more sense to my users if they can organize their plugins (which is reflected in the tool) via directories.
JasCav
You could also check the file's/folder's attributes to exclude all recycler folders.
0xA3
@divo - Yeah, I am going to watch the path and look for the term RECYCLER. If I see that, I know to ignore it. Thanks for your help.
JasCav