Why the open file handle ? [modified]
-
I am writing an simple application that will delete a file/directory. The application recives the target file as an argument. I have also put a shortcut in the W Explorer contextual menu, via Shell registry subkey of the folder entry in the HKEY_CLASSES_ROOT. [HKEY_CLASSES_ROOT\Folder\shell\NewMenuOption] @="Wipe it ..." [HKEY_CLASSES_ROOT\Folder\shell\NewMenuOption\command] @="D:\\FileWiper\\bin\\Debug\\FileWiper.exe \"%1\"" If a launch the program from a shell with an filename/folder as an argument it does it's job. But if the program is launched via the option in the Explorer menu and the selected targer is a folder (with a simple file it works), then the deleting fails with the exception " ... file being used by another process". It seems that the program keeps an open handle on the directory. The delete operation is made via Directory.Delete() ( tried also working with DirectoryInfo ...same result). Any one has any idea how can I get past this ? ------------------------------------------------------------------ LATER EDIT : I managed to track the problem after all. Simple stuff really, but forgot about it. Windows set the current directory for the program was set to be the target directory, so a simple change of the current directory was enough to get the program going. -- modified at 4:04 Friday 9th March, 2007