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

如何用PowerShell复制多版本发布目录下的Patch目录并保留原层级结构

PowerShell 实现代码

# 定义源根目录与目标根目录,可根据实际路径修改
$sourceRoot = "\Releases"
$targetRoot = "C:\Temp\eureka"

# 筛选符合版本规则的app版本目录
$matchVersionDirs = Get-ChildItem -Path $sourceRoot -Directory -Filter "app_26.6.*" | Where-Object {
    $versionSegments = $_.Name.Split('.')
    # 校验版本号第三段取值为1-7
    $versionSegments.Count -ge 3 -and $versionSegments[2] -match '^[1-7]$'
}

# 遍历复制Patch目录,保留层级结构
foreach ($dir in $matchVersionDirs) {
    $patchSourcePath = Join-Path -Path $dir.FullName -ChildPath "Patch"
    if (Test-Path -Path $patchSourcePath -PathType Container) {
        $patchTargetPath = Join-Path -Path $targetRoot -ChildPath "$($dir.Name)\Patch"
        Copy-Item -Path $patchSourcePath -Destination $patchTargetPath -Recurse -Force
    }
}

关键逻辑说明

  • 版本匹配:通过分割目录名称校验版本号第三段取值范围,完全符合26.6.[1-7].*的规则
  • 层级保留:直接复用原版本目录名称拼接目标路径,自动保留父目录\子目录的结构
  • 异常兼容:增加了Patch目录存在性判断,避免无Patch目录的版本抛出执行错误
  • 若不需要覆盖目标路径已存在的文件,删除Copy-Item后的-Force参数即可

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.28 02:54:04