code . is not recognized as an internal or externa

2019-03-25 16:47发布

问题:

I want to open directory using cmd in visual studio code but its give me error in cmd. So, What setting is require for that?

I have performed below command

D:\RND>code .

回答1:

It needs to be setup so that Code is found in your PATH.

  1. Launch VS Code
  2. Open up command palette (press F1) and type shell command to find Shell Command: Install 'code' command in PATH command.
  3. Restart terminal

You can also set the PATH manually by adding:

C:\Program Files (x86)\Microsoft VS Code\

to your PATH environment variable.

  1. Open command prompt
  2. type setx path "%path%;C:\Program Files (x86)\Microsoft VS Code"
  3. Restart terminal


回答2:

For me it was due to not running cmd as an administrator. (Right click Command Prompt -> Run as Administrator)



回答3:

Make sure you know where is the installation of VS Code, it can be in Program Files (x86) if you installed the 32bits version or Program Files if you installed the 64bits version VS Code location Once you know that Run (Win+r) cmd and type: setx path "%path%;C:\Program Files (x86)\Microsoft VS Code"

or

setx path "%path%;C:\Program Files\Microsoft VS Code"

after that, you can type code . to open VS Code with the project of the current folder.