問題描述
我在 vscode 的 tasks.json 文件中定義了一個任務,如下所示
<代碼>{版本":0.1.0",任務": [{命令":吞咽","taskName": "eslint_task",參數":[埃斯林特","- 文件",${文件}"],回聲命令":真}]}
${file}
為我提供了運行此命令的文件的絕對路徑(在 macOS 中從 /Volumes
開始).有什么方法可以獲取同一文件的相對路徑(從工作區文件夾開始的路徑)?
我已經查看了任務的官方文檔,但找不到任何那里的參數列表.
找到了答案.我只需要使用 ${relativeFile}
而不是 ${file}
.
這是我找到的占位符列表 -
${workspaceRoot}
:工作區根文件夾${file}
:保存文件的路徑${relativeFile}
:保存文件的相對路徑${fileBasename}
:保存文件的基本名稱${fileDirname}
:保存文件的目錄名${fileExtname}
:保存文件的擴展名(包括.)${fileBasenameNoExt}
:保存文件的基本名稱,不帶擴展名${cwd}
:當前工作目錄
來源:取自這里.p>
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
}
]
}
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.
Found the answer. I just need to use ${relativeFile}
instead of ${file}
.
Here's the list of placeholder I have found -
${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
Source: Taken from here.
這篇關于獲取vscode中任務文件的相對路徑的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!