我试图用PowerShell使用technique outlined in another SO question将文件的格式转换为UTF-8。Powershell - WriteAllLines方法 - '访问被拒绝'
我使用下面的语句:
[IO.File]::WriteAllLines((Get-Item -Path ".\" -Verbose).FullName,"Test.txt")
第一个参数是文件路径(C:\用户\ rsax \文件\测试),第二个参数是文件的名称。
但是,该命令不能正常工作,并返回以下错误:
Exception calling "WriteAllLines" with "2" argument(s): "Access to the path 'C:\users\rsax\documents\Test' is denied."
At line:1 char:25
+ [IO.File]::WriteAllLines <<<< ((Get-Item -Path ".\" -Verbose).FullName,"Test.txt")
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
- 我从PowerShell中运行命令为管理员。
- 我已验证该文件在文件夹中。
我可以运行在访问该文件的目录其他cmdlet,例如 如:
获取内容的Test.txt | Out-File TestOut.txt
我无法在MSDN MethodInvocationException page上找到答案。
我在做什么错?
第一个参数应该是完整的路径,而不仅仅是目录。第二个参数是源内容。 – TheMadTechnician