简体   繁体   中英

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 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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM