【发布时间】:2017-05-19 16:34:04
【问题描述】:
你能解释一下有什么区别吗
$attachment = [String]::Concat($workingDir,"\", $fileName)
和
$attachment = [IO.Path]::Combine($workingDir, $fileName)
当谈到在 Powershell 中组合路径时?
【问题讨论】:
标签: .net powershell
你能解释一下有什么区别吗
$attachment = [String]::Concat($workingDir,"\", $fileName)
和
$attachment = [IO.Path]::Combine($workingDir, $fileName)
当谈到在 Powershell 中组合路径时?
【问题讨论】:
标签: .net powershell
考虑$workingDir 有一个尾部反斜杠而$fileName 有一个前导反斜杠的情况,例如:
$workingDir = "C:\foo\"
$fileName = "\bar.txt"
这 2 个命令将产生以下结果:
PS C:\> [String]::Concat($workingDir, "\", $fileName) C:\foo\\\bar.txt PS C:\> [IO.Path]::Combine($workingDir, $fileName) \bar.txt在 PowerShell 中最好使用Join-Path:
【讨论】:
Path.Combine 方法在语义上可以识别文件夹路径。例如,如果 $workingDir 是 "c:\",那么 String.Concat 示例将生成带有两个相邻反斜杠的路径。
【讨论】: