powershell - 如何删除 PowerShell 说不存在的文件?
问题描述
我将我的 Google Drive 添加到我的 OneDrive 并在其中有一个包含无效名称 (con.mp3) 的文件。当我试图删除文件(及其所在的目录)时,我得到“无效的文件句柄”。所以我尝试以管理员身份使用 PowerShell 将其删除。
这是显示文件的目录列表,以及 和 的Remove-Item
结果del
。
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 Drive 中删除它,但它没有同步到我的计算机。
解决方案
保留字con
不应用作路径/文件名(或部分)。
删除时您必须使用-LiteralPath
参数并最终使用前缀。\\?\
所以试试:
Remove-Item -LiteralPath "\\?\C:\Users\Patrick\OneDrive\Google Drive\CW\CW.15WPM.VeryShortWords\con.mp3" -Force
如果这不起作用,您可以在 cmd 窗口中尝试:
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 -系统卷
推荐阅读
- vue.js - 如何在外部 oauth2 完成后重新获取 apollo vuejs
- spring-cloud-stream - Spring Cloud Stream Kinesis Binder 错误处理
- r - 如何按列和行对值求和,如 Excel 中的数据透视表?
- java - 飞碟无法识别 html 实体
- python - Django request.data.get('submit') 始终没有返回,即使 name 提供为 name="submit"
- ios - 命令行 Swift 构建 - libswiftCore.dylib 的此副本需要 10.14.4 之前的操作系统版本
- jsp - 如何让 RequestDispatcher 转发到位于单独文件夹中的所需 jsp?
- sql - ROW_NUMBER() OVER 在单列上使用 ORDER BY 很慢
- r - 根据密度(频率)画一个有颜色的圆
- php - PHP:聚合数组