問(wèn)題描述
我在 vscode 的 tasks.json 文件中定義了一個(gè)任務(wù),如下所示
<代碼>{版本":0.1.0",任務(wù)": [{命令":吞咽","taskName": "eslint_task",參數(shù)":[埃斯林特","- 文件",${文件}"],回聲命令":真}]}
${file}
為我提供了運(yùn)行此命令的文件的絕對(duì)路徑(在 macOS 中從 /Volumes
開(kāi)始).有什么方法可以獲取同一文件的相對(duì)路徑(從工作區(qū)文件夾開(kāi)始的路徑)?
我已經(jīng)查看了任務(wù)的官方文檔,但找不到任何那里的參數(shù)列表.
找到了答案.我只需要使用 ${relativeFile}
而不是 ${file}
.
這是我找到的占位符列表 -
${workspaceRoot}
:工作區(qū)根文件夾${file}
:保存文件的路徑${relativeFile}
:保存文件的相對(duì)路徑${fileBasename}
:保存文件的基本名稱${fileDirname}
:保存文件的目錄名${fileExtname}
:保存文件的擴(kuò)展名(包括.)${fileBasenameNoExt}
:保存文件的基本名稱,不帶擴(kuò)展名${cwd}
:當(dāng)前工作目錄
來(lái)源:取自這里.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.
這篇關(guān)于獲取vscode中任務(wù)文件的相對(duì)路徑的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!