【发布时间】:2019-05-23 07:23:58
【问题描述】:
我使用的是 Windows 10。
当我尝试使用 Powershell 创建文件时,出现以下错误
(注意:同样的行为发生在 cmd.exe 但不是 Git Bash)
PS C:\Users\John\Documents> New-Item hi.txt -type file
New-Item : Could not find file 'C:\Users\John\Documents\hi.txt'.
At line:1 char:1
+ New-Item hi.txt -type file
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError:
(C:\Users\John\Documents\hi.txt:String) [New-Item],
FileNotFoundException
+ FullyQualifiedErrorId : NewItemIOError,Microsoft.PowerShell.Commands.
NewItemCommand
我可以从文件资源管理器和 Git Bash 正常创建、打开和更新文件。
我已经检查了目录的权限级别,并且我确实可以完全控制该目录。
PS C:\Users\John> (get-acl .\Documents\).access
FileSystemRights : FullControl
AccessControlType : Allow
IdentityReference : NT AUTHORITY\SYSTEM
IsInherited : False
InheritanceFlags : ContainerInherit, ObjectInherit
PropagationFlags : None
FileSystemRights : FullControl
AccessControlType : Allow
IdentityReference : BUILTIN\Administrators
IsInherited : False
InheritanceFlags : ContainerInherit, ObjectInherit
PropagationFlags : None
FileSystemRights : FullControl
AccessControlType : Allow
IdentityReference : BUILTIN\Users
IsInherited : False
InheritanceFlags : None
PropagationFlags : None
FileSystemRights : FullControl
AccessControlType : Allow
IdentityReference : JOHN-DEEPBOOK\JOHN
IsInherited : False
InheritanceFlags : ContainerInherit, ObjectInherit
PropagationFlags : None
FileSystemRights : FullControl
AccessControlType : Allow
IdentityReference : NT AUTHORITY\SYSTEM
IsInherited : True
InheritanceFlags : ContainerInherit, ObjectInherit
PropagationFlags : None
FileSystemRights : FullControl
AccessControlType : Allow
IdentityReference : BUILTIN\Administrators
IsInherited : True
InheritanceFlags : ContainerInherit, ObjectInherit
PropagationFlags : None
FileSystemRights : FullControl
AccessControlType : Allow
IdentityReference : JOHN-DEEPBOOK\JOHN
IsInherited : True
InheritanceFlags : ContainerInherit, ObjectInherit
PropagationFlags : None
尝试以管理员身份运行 PowerShell,结果同样如此。
这不是唯一存在此问题的目录。 /Desktop 和 /Contacts 也有同样的问题。我认为这些内置目录可能有一些特别之处,但 /Downloads 工作正常。它们都具有相同的权限级别。
我发现的另一个有趣的行为是,当我从 PowerShell 调用 Sublime 时,它遇到了无法保存文件的相同问题。但是当我从开始菜单调用它时,它工作正常。
我也尝试在 Vscode 中进行编辑,但当我尝试保存文件时它崩溃了。当我从 PowerShell 和开始菜单调用时,它都崩溃了。
这似乎更像是一个 Windows 问题,而不仅仅是 PowerShell,因为我在使用 cmd.exe 和 Vscode 时遇到了同样的问题。
如果您对为什么会发生这种情况有任何线索,欢迎提出任何建议!
【问题讨论】:
-
探索
$error并查看.exception看看是否可以获得更多信息。 -
您可以尝试使用 Sysinternal 的 Process Monitor 进行监控。
-
检查您的个人资料是否确实被重新定位,或者文档库是否也被重新定位。很可能您在访问重新定位的存储时遇到了一些问题。
标签: windows powershell visual-studio-code file-permissions