當您使用PowerShell中的.NET對象並且需要文件名時,它似乎總是相對於C:\Windows\System32
。爲什麼PowerShell中的.NET對象不使用當前目錄?
例如:
[IO.File]::WriteAllText('hello.txt', 'Hello World')
...會寫C:\Windows\System32\hello.txt
,而不是C:\Current\Directory\hello.txt
爲什麼PowerShell中做到這一點?這種行爲可以改變嗎?如果它不能改變,我該如何解決它?
我試過Resolve-Path
,但只適用於已經存在的文件,而且它太冗長了,無法一直做下去。
可能重複$ home,而不是當前目錄?](http://stackoverflow.com/questions/4071775/why-is-powershell-resolving-paths-from-home-instead-of-the-current-directory) –