如何访问位于 Windows(如 "CON")上具有保留系统名称的文件夹中的本地文件?

How to access a local file located in a folder with a reserved system name on Windows like "CON"?

我需要访问位于包含名为 con 的文件夹的本地路径下的文件。 connul 等文件夹名称保留供特定系统任务使用,尝试访问此类目录下的文件将导致以下消息:

如果我无法更改此类文件夹的名称,我该如何访问此类文件?

我注意到可以使用以下命令在命令提示符中创建此类文件夹名称:

md con\

并且可以通过以下方式删除:

rd /q /s con

此外,使用资源管理器将文件拖入文件夹也可以成功添加文件。

我也尝试过使用 git-bash 来创建、删除和打开此类目录的内容,但是当我尝试从 windows, 文件即使明明在路径中也无法访问。

按照 here, that should work fine in PowerShell as shown in this example.

的描述在其前面加上 \?\
PS C:\temp\posh> gci
PS C:\temp\posh> cmd /c "md con\"
PS C:\temp\posh> gci


    Directory: C:\temp\posh


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----         12-06-18     09:24                con


PS C:\temp\posh> rm -LiteralPath '\?\c:\temp\posh\con\'
PS C:\temp\posh> gci
PS C:\temp\posh>

以下是使用 PowerShell 在具有保留名称的文件夹中写入和读取文件的方法:

PS C:\temp\posh> "test" | out-file -LiteralPath "\?\c:\temp\posh\con\test.txt"
PS C:\temp\posh> Get-Content -LiteralPath "\?\c:\temp\posh\con\test.txt"
test
PS C:\temp\posh>

试试这些步骤:

警告:我以前没有尝试过这种方法。请务必在开始前备份您的文件。

  1. 通过单击 here
  2. 下载并安装 'Run as System tool'
  1. 运行 应用程序并输入 'cmd.exe'
  2. 当您看到命令提示符 window 时,键入 cd C:\con
  3. 如果允许您访问该文件夹,请键入 'dir' 以查看 con
  4. 中的文件

如果你对我写这些步骤的原因感到好奇,请看下面。

我认为这种方法会奏效,因为 SYSTEM 帐户可能有权访问 con,因此查看 con 的内容可能与 运行 cmd 作为 SYSTEM 用户


尽情享受

强森佐治