在vscode中获取任务的文件的相对路径 [英] Get relative path of the file for tasks in vscode
问题描述
我在vscode的task.json文件中定义了一个任务,如下所示:
I have a task defined in vscode's tasks.json file as following
{
"version": "0.1.0",
"tasks": [
{
"command": "gulp",
"taskName": "eslint_task",
"args": [
"eslint",
"--file",
"${file}"
],
"echoCommand": true
}
]
}
${file}
为我提供了我在其上运行此命令的文件的绝对路径(从macOS中的/Volumes
开始).有什么办法可以获取同一文件的相对路径(从工作区文件夹开始的路径)?
The ${file}
is providing me the absolute path (starting from /Volumes
in macOS) of the file on which I run this command. Is there any way I can get the relative path (Path starting from the workspace folder) of the same file instead?
我已经检查了任务的官方文档,但是找不到任何文档那里的参数列表.
I already checked the official documentation for tasks, but couldn't find any list of arguments there.
推荐答案
找到了答案.我只需要使用${relativeFile}
而不是${file}
.
Found the answer. I just need to use ${relativeFile}
instead of ${file}
.
这是我找到的占位符列表-
Here's the list of placeholder I have found -
-
${workspaceRoot}
:工作区根文件夹 -
${file}
:已保存文件的路径 -
${relativeFile}
:保存文件的相对路径 -
${fileBasename}
:保存文件的基本名称 -
${fileDirname}
:已保存文件的目录名称 -
${fileExtname}
:已保存文件的扩展名(包括.) -
${fileBasenameNoExt}
:保存文件的基本名称,不带扩展名 -
${cwd}
:当前工作目录
${workspaceRoot}
: workspace root folder${file}
: path of saved file${relativeFile}
: relative path of saved file${fileBasename}
: saved file's basename${fileDirname}
: directory name of saved file${fileExtname}
: extension (including .) of saved file${fileBasenameNoExt}
: saved file's basename without extension${cwd}
:current working directory
来源:摘录自此处.
这篇关于在vscode中获取任务的文件的相对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!