Is there a way to open all files in a directory in the current workspace using the VS Code CLI?

Viewed 261

I want to open all files under /var/log/my_program/ in my current open workspace. To be clear, I want to open the files from this directory while keeping the files that are already open in my current workspace open as well.

e.g. if I have ~/hello-world.html open, I would like to open /var/log/my_program/error.log and /var/log/my_program/access.log in the workspace as well, having a total of 3 files open at the same time in the same window/workspace.

if I run code /var/log/my_program/* it will open up a new window with all of the files open from that directory. i.e. hello-world.html will be in one window and error.log and access.log will be in a new window

if I run code -r /var/log/my_program/* it will overwrite my current workspace with the files from that directory. i.e. hello-world.html will no longer be open in any window, and error.log and access.log will be open in my original workspace window.

I want to be able to keep the state of my current workspace AND open the files from the /var/log/my_program/ directory. i.e. I would like hello-world.html to stay open in the workspace AND have error.log and access.log open as well.

I would like to add that this is just a simplified example of what I am trying to do. I understand it would be easy enough to just open these two files easily in the command line, but the actual files in the dir I want to open could be several and all with timestamps in their names, so I cant easily open them by name

Is this possible? Thanks for any help!

EDIT: I am really looking for a solution using the CLI. I am running a command similar to rm /var/log/my_program/*; systemctl restart my_program; code /var/log/my_program/*. This is so the dir doesnt get full of old log files, and I can see the new log files opened after I have restarted the process for my_program

The reasoning for all of this is to make my debugging routine less cumbersome, e.g. without mouse clicks or gui interaction

2 Answers

In VS CODE itself there is a keyboard shortcut that might be helpful: ctrl + r Which will open a drop down of folders. Once you arrow down/up to the desired folder, you have two options: Click enter to open the new folder instead of the current workspace, or ctrl + enter to open a new folder in addition to the current open workspace

If I understand what you are trying to do correctly, you want to use the --add argument. You can run code --reuse-window --add <path> to open the folder at <path> in the current workspace. The shortened version would be code -r -a <path>.

Related