You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在PowerShell中将两个不同路径合并到同一个对象中

PowerShell 多源路径拼接调整方案

你当前写法的问题是Join-Path的-ChildPath参数不支持一次性传入多个路径值批量拼接,无法直接生成包含两个完整目标路径的数组。

调整代码

你可以通过遍历子路径分别拼接的方式实现需求,兼容所有PowerShell版本:

$RetailSource  = '\Retail P&C Sales Intelligence\*'
$GroupSource = '\Group P&C Sales Intelligence\*'
$sourcepath = $RetailSource, $GroupSource | ForEach-Object {
    Join-Path -Path 'c:\uploadtool' -ChildPath $_
}

如果不需要处理跨平台路径分隔符兼容,也可以用更简单的字符串拼接写法:

$basePath = 'c:\uploadtool'
$RetailSource  = '\Retail P&C Sales Intelligence\*'
$GroupSource = '\Group P&C Sales Intelligence\*'
$sourcepath = "$basePath$RetailSource", "$basePath$GroupSource"

后续使用说明

生成的$sourcepath是包含两个完整路径的数组,可直接传入Get-ChildItem使用:

Get-ChildItem -Path $sourcepath

注意原代码中的&是HTML转义字符,实际编写代码时直接使用&即可。


内容的提问来源于stack exchange,提问作者essex lake

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.19 18:06:03