为什么 PowerShell 从 $home 而不是当前目录解析路径? [英] Why is PowerShell resolving paths from $home instead of the current directory?
本文介绍了为什么 PowerShell 从 $home 而不是当前目录解析路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望这个小小的 powershell one liner 能够回显到 foo.txt 的完整路径,其中的目录是我的当前目录.
I expect this little powershell one liner to echo a full path to foo.txt, where the directory is my current directory.
[System.IO.Path]::GetFullPath(".\foo.txt")
但事实并非如此.它打印...
But it's not. It prints...
C:\Documents and Settings\Administrator\foo.txt
我不在 $home 目录中.为什么会在那里解决?
I am not in the $home directory. Why is it resolving there?
推荐答案
[System.IO.Path]
正在使用 shell 进程的当前目录.您可以使用 Resolve-Path
cmdlet 获取绝对路径:
[System.IO.Path]
is using the shell process' current directory. You can get the absolute path with the Resolve-Path
cmdlet:
Resolve-Path .\foo.txt
这篇关于为什么 PowerShell 从 $home 而不是当前目录解析路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文