Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get relative path of the file for tasks in vscode

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.

like image 813
noob Avatar asked Apr 12 '17 09:04

noob


People also ask

How do I get the relative path of a file in Visual Studio Code?

Press Ctrl+Shift+H (Mac: Cmd+Shift+H ) and start typing the file you want. 🪄 Select your file from the dropdown!

How do I find the path of a directory in VS Code?

Using ctrl+P (or cmd+P) is however an easy way to do this. Simply put /myfolder or folder/file or even folder/*/file . You'll see files contained by that folder and the full path so.. like finding the folder.

Where Is tasks json VS Code?

You need to configure the tasks in a tasks. json file (located under your workspace . vscode folder) if you want to do more than simply run the task. For example, you might want to match reported problems and highlight them within VS Code, or to trigger a build task using the Run Build Task command ( kb(workbench.

What is path Intellisense in VS Code?

Visual Studio Code plugin that autocompletes filenames.


1 Answers

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.

like image 200
noob Avatar answered Sep 20 '22 09:09

noob