Access to path is denied when moving a directory, but is able to create folders in the directory
I am writting a simple program that moves Directory A in C Drive to Directory B in C Drive by 开发者_StackOverflow社区using the following code
System.IO.Directory.Move(DirectoryA, DirectoryB);
Strangely, it throws an exception, saying the Access to Directory A is denied.
However, then I tried creating a folder in Directory A, by System.IO.Directory.CreateDirectory(DirectoryA+ @"\test");
. I had no problem creating the test Directory within DirectoryA, so I guess it is not a permission problem.
So I have no idea what the problem is, the code was working before, so does anyone have any idea at all, thanks :)
Windows differentiates between "Create" and "Modify" permissions; you can have rights to do one but not the other. IIRC, "Delete", which is what is required to "move" a folder from a given place (basically deleting it in that place and creating it in another) is also separate; it's actually a special permission that can be granted by itself or by granting "full control".
Move is essentially a copy and delete operation, right? And the ACL permissions for deleting a directory and adding subdirectories to it would be different permissions. So I suppose you could theoretically have the correct permissions to modify the directory, but not to delete it. Have you confirmed the security permissions on DirectoryA?
精彩评论