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

VSCode tasks.json中pickFile输出路径转换问题求助

解决方案

修改你的tasks.json配置,通过extension.commandvariable.transform对选中的文件路径进行正则替换,提取出你需要的文件名部分:

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "build",
      "type": "shell",
      "command": "${userHome}/build.py",
      "args": ["param_def=${input:pickBuild}"]
    }
  ],
  "inputs": [
    {
      "id": "pickBuild",
      "type": "command",
      "command": "extension.commandvariable.transform",
      "args": {
        "command": "extension.commandvariable.file.pickFile",
        "args": {
          "include": "**/default_*.py",
          "description": "Select build",
          "display": "fileName"
        },
        "transform": {
          "find": "^.*\\/(default_.*)\\.py$",
          "replace": "$1"
        }
      }
    }
  ]
}

关键说明

  • 外层使用extension.commandvariable.transform作为输入命令,嵌套调用file.pickFile获取选中的文件路径
  • transform配置里的正则表达式^.*\/(default_.*)\.py$会匹配完整文件路径,捕获default_开头到.py之前的部分
  • 替换为$1即可得到你需要的default_android格式的字符串

这样执行build任务时,生成的命令就会是你期望的:/home/user/build.py param_def=default_android

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.07 19:25:40