1

Does Visual Studio Code have a built-in function or if there is a plugin that can open all the files I give it at once (as a single action)?

Occasionally I have this requirement where I get a list of file paths and I would like to open all of them in VS Code. Sometimes I create a small script that does that (just calls "code.exe" multiple times), but I'm wondering if perhaps there is a simpler way.

starball
  • 20,030
  • 7
  • 43
  • 238
hertzogth
  • 236
  • 1
  • 2
  • 19
  • 1
    Does this answer your question? [How can multiple files be opened in Visual Studio Code (VSC)?](https://stackoverflow.com/questions/50827846/how-can-multiple-files-be-opened-in-visual-studio-code-vsc) – GSerg Apr 21 '23 at 10:41
  • 1
    @GSerg unfortunately no, the files that I have are not in the same folder. Best to think of it as if the files could be anywhere on the disc. – hertzogth Apr 21 '23 at 11:36
  • 1
    What format is your list of files in? Give an example please. – Mark Apr 21 '23 at 15:55

2 Answers2

3

If you run code --help, you'll see "Usage: code [options][paths...]".

So just run code <file path 1> <file path 2> <file path 3> <...> in whatever shell of your choice. Make sure to use shell-appropriate quoting if any of the file paths have spaces in them. And you can use relative paths relative to the current working directory of the shell.

If you already have a VS Code window open, doing so will open those files in the existing window. If you want to open them in a new VS Code window, use the -n (also aliased as --new-window) flag.

Note also that the File > Open mechanism supports opening multiple files at the same time. You'll have to use whatever keyboard modifiers are used by your platform (OS)'s native File Explorer application, but usually, it's holding ctrl/cmd to add a single item to the selection, and holding shift to add a range of consecutive items to the selection.

starball
  • 20,030
  • 7
  • 43
  • 238
  • Great, thank you! Can you also add to your answer that the "File" -> "Open File" action (CTRL + o) accepts multiple files as well, they just need to be quoted appropriately. – hertzogth Apr 21 '23 at 12:07
  • @hertzogth mostly done. see edit. but what do you mean by "quoted properly"? – starball Apr 21 '23 at 17:53
1

With the extension File Group v1.2.0 (that I wrote) you can use the content of the active editor as file paths and load all the files or first make a selection (multi cursor).

If the file paths are not absolute you can add variables to construct an absolute path using the file path of the editor file.

From the Command Palette or editor context menu you can open the selected file paths or all.

  • File Group: Open Files in Active Column
  • File Group: Open Files in Split Column
  • File Group: Open Files in Side Column
  • File Group: Open Files in Column 1
  • File Group: ....
rioV8
  • 24,506
  • 3
  • 32
  • 49