When renaming a folder in C#, System.IO.Directory.Move
throws System.IO.IOException
(message "access denied") if that folder or any subfolder is currently opened by a (Windows 7) explorer window.
Using the commandline RENAME
fails, too.
Using a second explorer windows succeeds.
The error persists even after collapsing the parent folder (or its parents). In fact the particular explorer window needs to be closed. So the explorer seems to create some locks just to show the folder structure and does not release them even if the actual folder isnt displayed anymore (which is pure nonsens IMO).
Is there a way to rename a folder (in program e.g. using C#), that is presently displayed (or was visible, see above) by an explorer window?
Update
Found a way as described by my own answer to this question (see below) using SHFileOperation()
. However, this solution is not very feasible (see also below).