jba*_*991 2 string powershell filepath
我有以下内容:
function createFolder($folderName, $curPath)
{
$dest = $curPath + $folderName
write-host "Path is : " + $dest
# code to mess around with files etc
}
Run Code Online (Sandbox Code Playgroud)
当我运行它时,它会给出以下输出:
function createFolder($folderName, $curPath)
{
$dest = $curPath + $folderName
write-host "Path is : " + $dest
# code to mess around with files etc
}
Run Code Online (Sandbox Code Playgroud)
我是否缺少运算符+或适用于此类函数的 join/concat 方法?在 PowerShell 中创建/连接/操作路径的正确方法是什么(我刚刚开始使用它来自动执行桌面上的一些清理任务)。
编辑:如果它有所不同,这就是我运行版本命令时看到的内容:
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.
Run Code Online (Sandbox Code Playgroud)
另外,我使用的是没有管理权限的工作计算机。
我试过:
$currentPath = "C:\Users\n0223270\Downloads"
$test = "test"
createFolder($test, $currentPath)
function createFolder($folderName, $curPath)
{
$dest = join-path -path $curPath -childpath $folderName
Write-Host $dest
}
Run Code Online (Sandbox Code Playgroud)
这是以下错误:
Path is : + Test_Folder C:\Users\Me
Run Code Online (Sandbox Code Playgroud)
createFolder($test, $currentPath)
这不是调用 Powershell 函数的方式。这是将第一个参数作为两个字符串的数组传递。第二个参数将为 null,因为它未指定且没有默认值。
尝试:
createFolder $test $currentPath
Run Code Online (Sandbox Code Playgroud)