简体   繁体   English

为什么我在尝试清除目录的内容时收到消息“拒绝访问路径 'bootmgr'”

[英]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:一种解决方案:

  • change your code st It only selects files without a leading dot, like with regex: ^\.更改您的代码 st 它只选择没有前导点的文件,例如使用正则表达式: ^\.

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.

相关问题 当我尝试使用MemoryMappedFile类来映射/ dev / mem的内容时,为什么会出现“拒绝访问路径”? - Why do I get “Access to the path is denied” when I try to use a MemoryMappedFile class to mmap the contents of /dev/mem? 为什么我在尝试连接到“localhost”时会收到“拒绝访问”错误? - Why do I get an 'Access Denied' error when trying to connect to 'localhost'? 为什么我在尝试打印到 PDF 时收到错误:“访问被拒绝”? - Why do I get the error: “Access is denied” when trying to print to a PDF? 使用Directory.GetFiles(...)时,我得到异常“拒绝访问路径” - When using Directory.GetFiles(…) , I get exception “Access to the path is denied” 为什么我得到System.UnauthorizedAccessException拒绝访问路径'Google.Apis.Auth'被拒绝 - Why do I get System.UnauthorizedAccessException Access to the path 'Google.Apis.Auth' is denied 重命名目录时,错误访问路径被拒绝 - Error Access to the path is denied when Rename a Directory 为什么在我尝试移动目录时访问被拒绝? - Why is access denied when I try to move a directory? 尝试上传文件时拒绝访问路径 - Access to path is denied when trying to upload file 访问目录路径被拒绝 - Access to the directory path is denied 尝试将json文件写入应用程序目录时,UWP“拒绝访问路径'...'” - UWP “Access to the path '…' is denied” when trying to write a json file to the app directory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM