简体   繁体   English

移动目录时拒绝访问路径,但能够在目录中创建文件夹

[英]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 我正在编写一个简单的程序,使用以下代码将C盘中的目录A移动到C盘中的目录B.

System.IO.Directory.Move(DirectoryA, DirectoryB);

Strangely, it throws an exception, saying the Access to Directory A is denied. 奇怪的是,它抛出一个异常,说拒绝访问目录A.

However, then I tried creating a folder in Directory A, by System.IO.Directory.CreateDirectory(DirectoryA+ @"\\test"); 但是,我尝试通过System.IO.Directory.CreateDirectory(DirectoryA+ @"\\test");在目录A中创建一个文件夹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. 我在DirectoryA中创建测试目录没有问题,所以我想这不是权限问题。

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; Windows区分“创建”和“修改”权限; 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; IIRC,“删除”,这是从一个给定的地方“移动”一个文件夹所需要的(基本上在那个地方删除它并在另一个地方创建它)也是分开的; 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? Move本质上是一个复制和删除操作,对吧? And the ACL permissions for deleting a directory and adding subdirectories to it would be different permissions. 用于删除目录和向其添加子目录的ACL权限将是不同的权限。 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? 您是否确认了DirectoryA的安全权限?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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