Are there variables for the current file or folder in the VS Code terminal?

When in the terminal scope, I would like to reference the file or folder of the active editor tab via an environment variable or PowerShell variable (preferred). Something like that:

ii $vsActivePath

or

ii $vsActiveFile

Is it possible?

+3


source to share


2 answers


Not sure if this is exactly what you are looking for, but you can access various variables in your code, for example:

${workspaceRoot} the path of the folder opened in VS Code
${workspaceRootFolderName} the name of the folder opened in VS Code without any slashes (/)
${file} the current opened file

      



More information can be found here

+2


source


They have added a few new variables and contain ${fileDirname}

which is the path to the directory your current is in ${file}

. The documentation seems to be a little misleading.

These are the currently available options:



${workspaceFolder} - the path of the folder opened in VS Code
${workspaceFolderBasename} - the name of the folder opened in VS Code without any slashes (/)
${file} - the current opened file
${relativeFile} - the current opened file relative to workspaceFolder
${fileBasename} - the current opened file basename
${fileBasenameNoExtension} - the current opened file basename with no file extension
${fileDirname} - the current opened file dirname
${fileExtname} - the current opened file extension
${cwd} - the task runner current working directory on startup
${lineNumber} - the current selected line number in the active file

      

0


source







All Articles