powershell [System.IO.File]::WriteAllLines 不工作

标签 powershell filepath working-directory

这些 PowerShell 命令有什么问题。它不会写入文件“test.txt”

PS> $stuff = @("AAA`n", "BBB`n")
PS> [System.IO.File]::WriteAllLines(".\test.txt", $stuff)
PS> dir
# Nothing here....

我的计算机上是否有任何配置错误可能导致此问题?我需要以某种方式重新安装.net吗?

最佳答案

尝试dir ~\test.txt - 或使用绝对路径c:\path\to\my\test.txt。最好看看 Set-Content cmdlet。

仅供引用:您的计算机没有任何问题 - 您使用的是 dotnet 库,因此您需要更具体(基本上)。 Set-Content 是执行此操作的 powershell 方式(并且 .\test.txt 将按照您的预期工作)。

关于powershell [System.IO.File]::WriteAllLines 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69682081/

相关文章:

javascript - 如何通过Node JS(或命令行)更改系统音频输出/输入设备

powershell - Get-ChildItem递归作为PowerShell中的参数

Python 原生解析具有未知路径分隔符的路径名

haskell - 将 Haskell 的 GHCi 中的工作目录更改为带空格的路径

xml - 为什么将对象列表导出到 CSV 会返回 System.Object[]?

powershell - 以异步方式使用 Powershell 的 BeginInvoke() 和 EndInvoke()

git - 如何将工作目录设置为较旧的提交?

Mercurial:将补丁应用到工作目录

python - 如何将具有绝对文件路径的字典转换为类似文件夹结构的嵌套字典?

apache - PHP : Include path that works both on Dev and Live