[英]Why do I get message “Access to the path 'bootmgr' is denied ” when trying to clear the contents of a directory
Using Windows 10 Home (20H2) on HP Spectre在 HP Spectre 上使用 Windows 10 Home (20H2)
I am trying to use the following code to clear the contents of a directory我正在尝试使用以下代码清除目录的内容
public int clearDirectory(string path)
{
DirectoryInfo targetDir = new DirectoryInfo(path);
foreach (FileInfo file in targetDir.GetFiles())
{
file.Delete();
}
foreach (DirectoryInfo dir in targetDir.GetDirectories())
{
dir.Delete(true);
}
return 0;
}
The target directory is on a USB SanDisk which has in its root dir one directory (which has a number of subdirectories) which I created and the following SanDisk files目标目录位于 USB SanDisk 上,它的根目录中有一个我创建的目录(其中有许多子目录)和以下 SanDisk 文件
SanDiskMemoryZone_AppInstaller.apk
SanDiskMemoryZone_QuickStartGuide.pdf
I replaced the path to the USB drive with a path to a directory on my C drive and that worked fine.我用 C 驱动器上的目录路径替换了 USB 驱动器的路径,并且效果很好。
How does the bootmgr get involved in this? bootmgr 如何参与其中?
In Windows you can declare for each drive if it is bootable or not.在 Windows 中,您可以声明每个驱动器是否可引导。 The bootable partition in Windows is a hidden drive called system partition (and that's also the reason why no error was shown when you tried to delete the C:-drive)
Windows 中的可引导分区是一个称为系统分区的隐藏驱动器(这也是您尝试删除 C:-drive 时没有显示错误的原因)
Your SAN-drive seems to be using a file system which has a hidden folder with ACL only for the system account.您的 SAN 驱动器似乎正在使用一个文件系统,该文件系统具有一个仅用于系统帐户的带有 ACL 的隐藏文件夹。
That's why you get this error.这就是您收到此错误的原因。 You have no access right to delete the file/folder.
您无权删除文件/文件夹。
One solution:一种解决方案:
^\.
^\.
If this still doesn't fix your error then you should try use an elevated process (with adminr rights) to tackle this.如果这仍然不能解决您的错误,那么您应该尝试使用提升的进程(具有管理员权限)来解决这个问题。
REMARK: before you delete everything from a usb stick, it would be easier to just reformat it then deleting every file.备注:在从 usb 记忆棒中删除所有内容之前,重新格式化它然后删除每个文件会更容易。 Maybe look into Diskpart for this.
也许为此研究Diskpart 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.