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

批量将同名.xml与.vid文件压缩为.zep的PowerShell脚本需求

PowerShell脚本批量压缩同名.xml和.vid文件为.zep文件

以下是实现批量处理的PowerShell脚本,自动匹配同名的.xml和.vid文件并打包为对应的.zep文件:

内置压缩版本(无需额外工具)

适用于.zep本质为ZIP格式的场景,直接用PowerShell内置命令完成:

# 获取当前目录下所有XML文件
$xmlFiles = Get-ChildItem -Filter *.xml

foreach ($xml in $xmlFiles) {
    # 提取不带扩展名的基础文件名
    $baseName = $xml.BaseName
    # 拼接对应的VID文件路径
    $vidFile = Join-Path -Path $xml.DirectoryName -ChildPath "$baseName.vid"
    
    # 检查对应的VID文件是否存在
    if (Test-Path -Path $vidFile) {
        $zepFile = Join-Path -Path $xml.DirectoryName -ChildPath "$baseName.zep"
        
        # 跳过已存在的ZEP文件,避免重复压缩
        if (-not (Test-Path -Path $zepFile)) {
            Compress-Archive -Path $xml.FullName, $vidFile -DestinationPath $zepFile -Force
            Write-Host "已生成: $zepFile"
        } else {
            Write-Host "已存在,跳过: $zepFile"
        }
    } else {
        Write-Warning "未找到匹配的VID文件: $vidFile"
    }
}

7-Zip版本(支持特定压缩需求)

如果.zep需要特定压缩算法或格式,可调用7-Zip工具完成(需提前安装7-Zip):

# 7-Zip的安装路径,请根据实际情况修改
$7zipPath = "C:\Program Files\7-Zip\7z.exe"

$xmlFiles = Get-ChildItem -Filter *.xml

foreach ($xml in $xmlFiles) {
    $baseName = $xml.BaseName
    $vidFile = Join-Path -Path $xml.DirectoryName -ChildPath "$baseName.vid"
    
    if (Test-Path -Path $vidFile) {
        $zepFile = Join-Path -Path $xml.DirectoryName -ChildPath "$baseName.zep"
        
        if (-not (Test-Path -Path $zepFile)) {
            # 调用7-Zip执行压缩,-tzip指定ZIP格式(可根据需求调整参数)
            & $7zipPath a -tzip $zepFile $xml.FullName $vidFile
            Write-Host "已生成: $zepFile"
        } else {
            Write-Host "已存在,跳过: $zepFile"
        }
    } else {
        Write-Warning "未找到匹配的VID文件: $vidFile"
    }
}

使用步骤

  1. 将上述脚本保存为BatchCompressToZep.ps1文件
  2. 把脚本放到包含目标文件的目录中
  3. 右键脚本文件选择「用PowerShell运行」,或在PowerShell中切换到该目录执行:.\BatchCompressToZep.ps1

关键说明

  • 脚本会自动跳过已生成的.zep文件,避免重复操作
  • 如果需要处理子目录中的文件,可在Get-ChildItem后添加-Recurse参数
  • 若出现权限问题,右键PowerShell选择「以管理员身份运行」后再执行脚本

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.17 13:50:26