Get relative path of the file for tasks in vscode
Asked Answered
P

1

14

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.

Parch answered 12/4, 2017 at 9:8 Comment(0)
P
26

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.

Parch answered 12/4, 2017 at 9:43 Comment(4)
anything for relativedirname ?Vernation
@SayanDey ${relativeFileDirname}. Full list available hereAmieeamiel
yeah got it beforeVernation
Just a reminder: in 2023, they have changed ${fileBasenameNoExt} to ${fileBasenameNoExtension}. Don't know the notion behind that change though...Haff

© 2022 - 2024 — McMap. All rights reserved.