顺序错误的变量连接

Variable concatenation in wrong order

我有以下内容:

function createFolder($folderName, $curPath)
{
    $dest = $curPath + $folderName
    write-host "Path is : " + $dest
    # code to mess around with files etc
}

当我 运行 这给了我以下输出:

Path is : + Test_Folder C:\Users\Me

+ 运算符或 join/concat 方法是否缺少某些用于此类功能的东西?在 PowerShell 中 create/concat/manipulate 路径的正确方法是什么(我刚开始使用它在我的桌面上自动执行一些清理任务)。

编辑:以防万一,这就是我在 运行 版本命令时看到的内容:

PS C:\Users\Me> version
BladeLogic Network Shell 8.2.01.273 (Release) [May 12 2012 21:56:02]
Copyright (C) 1996-2012 BladeLogic Inc.

此外,我在没有管理权限的工作计算机上。

我试过了:

$currentPath = "C:\Users\n0223270\Downloads"
$test = "test"
createFolder($test, $currentPath)

function createFolder($folderName, $curPath)
{
    $dest = join-path -path $curPath -childpath $folderName
    Write-Host $dest   
}

这是以下错误:

Join-Path : Cannot bind argument to parameter 'Path' because it is null.
At line:4 char:28
+     $dest = join-path -path <<<<  $curPath -childpath $folderName
+ CategoryInfo          : InvalidData: (:) [Join-Path], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.JoinPathCommand

createFolder($test, $currentPath)

这不是您调用 Powershell 函数的方式。这是将第一个参数作为两个字符串的数组传递。第二个参数将为空,因为它未指定且没有默认值。

尝试:

createFolder $test $currentPath