Powershell将环境变量与路径连接起来

时间:2016-12-08 19:15:02

标签: string environment-variables filepath powershell-v4.0

所以我有这段代码:

$userprofile=Get-ChildItem Env:USERPROFILE
$localpath="$userprofile\some\path"

我希望从$localpath输出以下内容:

c:\users\username\some\path

但我得到的是:

System.Collections.DictionaryEntry\some\path

因此,当然,cd $localpath之类的东西失败了。我如何实现我的需求?

1 个答案:

答案 0 :(得分:11)

获取字符串值而不是字典条目(在技术上是 for case let rowView in self.tableView.subviews { for case let tableviewCell as ContactInfoTableViewCell in rowView.subviews { tableviewCell.contactValue.resignFirstResponder() } } 正在访问的)的一种简便方法是使用变量语法:Get-ChildItem而不是$Env:USERPROFILE

Get-ChildItem Env:USERPROFILE

了解更多信息:

PowerShell Environment Provider

about_Environment_Variables

此外,Join-Path cmdlet是组合路径的两个部分的好方法。

$localpath = "$env:USERPROFILE\some\path"