How to change current working directory in VS Code?
Asked Answered
L

4

10

How to change current working directory in VS Code?

Let's say, I have a parent folder called apps and inside it I have a child folder called MyBeautifulApp and I opened the apps folder using vscode. What command sould I run on the commandline to not only cd into MyBeautifulApp but also change the directory so that it seems like I opened MyBeautifulApp using VS Code and did not just cd into it?

Lucan answered 18/6, 2021 at 5:30 Comment(0)
S
9

In File select Close Folder, and you will go back to the main menu, where you can select a new folder as the new working directory.

Stud answered 27/8, 2022 at 21:39 Comment(2)
Unfortunately there's no way to change the cwd using the File Explorer. This is the correct aproach to date.Bamako
That's terrible UI design.Volar
D
4

Just close Visual Studio Code and open it in the right folder again.

close program

code MyBeautifulApp/

OR

Press Command + O and open your folder.

Diffident answered 18/6, 2021 at 5:45 Comment(1)
Thank you. This I know. I just wanted a way that I do not have to close VS Code.Lucan
P
1

Reuse an Active Window

We can achieve this by using code --reuse-window path or use the short version code -r path This CLI will change the current directory of your VS code without opening a new window because as it name says it is reusing the active window

VS Code CLI

For more understanding of VS code CLI go to VS Code Official CLI

Or Hit code -h for more CLI references

Preexist answered 19/6 at 14:59 Comment(0)
T
1

Simply type:

code directoryName -r

If you are already in that directory:

code . -r

The -r flag replaces the current window with the new window. If you want to open a new window instead of replacing, skip the -r flag

Tolerate answered 12/8 at 7:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.