如何删除 PowerShell 指出不存在的文件?

How do I delete a file that PowerShell says does not exist?

我将我的 Google 驱动器添加到我的 OneDrive,并且其中有一个包含无效名称 (con.mp3) 的文件。当我尝试删除文件(及其所在的目录)时,我得到 "Invalid File Handle"。所以我尝试以管理员身份使用 PowerShell 删除它。

这是显示文件的目录列表,以及 Remove-Itemdel 的结果。

PS> dir

    Directory: C:\Users\Patrick\OneDrive\Google Drive\CW\CW.15WPM.VeryShortWords


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        1/13/2018  11:49 AM         117069 con.mp3


PS> Remove-Item * -Force
Remove-Item : An object at the specified path C:\Users\Patrick\OneDrive\Google
Drive\CW\CW.15WPM.VeryShortWords\con.mp3 does not exist.
At line:1 char:1
+ Remove-Item * -Force
+ ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Remove-Item], PSArgumentException
    + FullyQualifiedErrorId : Argument,Microsoft.PowerShell.Commands.RemoveItemCommand

PS> del *.*
del : An object at the specified path C:\Users\Patrick\OneDrive\Google Drive\CW\CW.15WPM.VeryShortWords\con.mp3 does
not exist.
At line:1 char:1
+ del *.*
+ ~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Remove-Item], PSArgumentException
    + FullyQualifiedErrorId : Argument,Microsoft.PowerShell.Commands.RemoveItemCommand

如何删除此文件,以便删除目录?我尝试将它从 Google 驱动器中删除,但它没有同步到我的计算机。

保留字 con 不应用作路径/文件名(或其一部分)。

您必须使用 -LiteralPath 参数并最终使用 \?\ 作为前缀 删除时。

所以尝试:

Remove-Item -LiteralPath "\?\C:\Users\Patrick\OneDrive\Google Drive\CW\CW.15WPM.VeryShortWords\con.mp3" -Force

如果这不起作用,您可以在 cmd 中尝试 window:

Del "\?\C:\Users\Patrick\OneDrive\Google Drive\CW\CW.15WPM.VeryShortWords\con.mp3"

如果这没有帮助,请阅读:
https://support.microsoft.com/en-us/help/320081/you-cannot-delete-a-file-or-a-folder-on-an-ntfs-file-system-volume

您可以尝试的另一件事是 运行 以下 CMD 命令 dir/A/X/P 然后 运行 del 命令针对列出的 MS-DOS 短名称。所以步骤可能是:

  1. 打开 cmd.exe(命令提示符)
  2. 将路径更改为包含文件 cd C:\Users\Patrick\OneDrive\Google Drive\CW\CW.15WPM.VeryShortWords
  3. 的目录
  4. 运行 dir/A/X/P 显示 MS-DOS 简称
  5. 使用 del 命令删除文件 short ms-dos name.