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

能否在VS Code的tasks.json中获取资源管理器选中目录作为变量?

实现VS Code tasks.json中使用资源管理器选中目录的方法

方法1:借助「Command Variable」扩展

  • 安装该扩展后,在tasks.json中使用其提供的内置变量直接获取选中目录:
    {
      "label": "Echo selected directory from explorer",
      "type": "shell",
      "command": "echo",
      "args": [
        "${command:extension.commandvariable.file.selectedFolder}"
      ],
      "problemMatcher": []
    }
    
  • 该变量会返回资源管理器当前选中目录的绝对路径,直接满足需求。

方法2:使用「Advanced Variables」扩展

  • 安装扩展后,可直接使用简化的变量:
    {
      "label": "Print selected directory",
      "type": "shell",
      "command": "echo",
      "args": [
        "${selectedFolder}"
      ],
      "problemMatcher": []
    }
    
  • 这个扩展还支持路径转换、相对路径等更多自定义能力,适配复杂场景。

说明

VS Code原生预定义变量确实没有直接获取资源管理器选中目录的能力,上述扩展方案是社区常用的轻量化解决方式,无需编写复杂脚本即可实现需求。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.01 22:53:24