Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running visual studio code in the current folder with batch file

I can follow below sequence of actions to run the Visual Studio Code in the current folder.

select the location bar in the current folder and run (ALT + D):

cmd /k code .

I've tried to wrap the code . in the batch file (and place it in a folder where is declared in the PATH variable to run it as its own), it launches "Visual Studio Code" but doesn't close the command window until i close the visual studio code.

i know "start" command need to be there with exit command in the end but so far the combinations i've tried didn't really let me achieve that.

cmd.exe /k code . exit

Any ideas?

like image 1000
Murat Kazanova Avatar asked May 01 '16 17:05

Murat Kazanova


People also ask

How do I run a batch file in VS Code?

Then, use the Tasks: Run Build Task hotkey ( Ctrl Shift B by default). You can have more than one such task. At most one task can have "isDefault": true , the one that Ctrl Shift B should run. Show activity on this post.

How do I open VS Code in a specific folder?

Go to the directory in the command pallet on your computer the navigate to the the specific folder using cd the type code . and that will open the folder and the files in it inside vs code. works like a charm.

Which command's do you use to open VS Code from the current directory?

If you already have a Terminal session running, quit or restart it. When you are in the directory of the files you want to open in VS Code, type code . (that is the word “code” followed by a space, then a period) and the folder will automatically open in VS code.


4 Answers

this works for me, Do not omit the first empty quote

Start "" "C:\Program Files (x86)\Microsoft VS Code\code.exe" <path_to_dir>\.

like image 166
pcreyght Avatar answered Oct 12 '22 13:10

pcreyght


This works for me (be sure to start code and exit at the bottom of the batch file):

start "" code
exit
like image 31
trank Avatar answered Oct 12 '22 13:10

trank


If you just want to start vscode from current folder from command line type

code %cd%

like image 26
Dvirus Avatar answered Oct 12 '22 13:10

Dvirus


Starts Visual Studio Code in current folder

@start code .

Starts Visual Studio Code in specific folder

@start code "<Specific Folder>"

Starts Visual Studio Code with a specific file

@start code "<Specific File>"

Save file as .bat

like image 24
Kamal Avatar answered Oct 12 '22 14:10

Kamal