這些 PowerShell 命令有什么問題。它不寫入檔案“test.txt”
PS> $stuff = @("AAA`n", "BBB`n")
PS> [System.IO.File]::WriteAllLines(".\test.txt", $stuff)
PS> dir
# Nothing here....
我的計算機上是否有任何配置錯誤可能導致此問題?我需要以某種方式重新安裝 .net 嗎?
uj5u.com熱心網友回復:
嘗試dir ~\test.txt或使用絕對路徑c:\path\to\my\test.txt。最好看看Set-Content cmdlet。
僅供參考:您的計算機沒有任何問題-您使用的是 dotnet 庫,因此您需要更具體(基本上)。Set-Content是執行此操作的 powershell 方式(并且.\test.txt會按您的預期作業)。
uj5u.com熱心網友回復:
.Net 不使用與 PowerShell 相同的路徑。解決方案是將相對路徑決議為完整路徑:
PS C:\> $stuff = @("AA", "BB")
PS C:\> $fullpath = $(Resolve-Path -Path ".\test.txt")
PS C:\>[System.IO.File]::WriteAllLines(`
".\testing.txt", $fullpath)
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/331879.html
標籤:电源外壳
