How can vscode print (or paste) all open file paths to a new file in the editor?

Viewed 784

In vscode Ctrl+Tab displays open files, but how can vscode print (or paste) the same 'all open file paths' to a new file in the editor?

1 Answers

If you have this setting set to a high enough number to show all your open files:

Editor > Open Editors: Visible

then you can select all the files from the Open Editors viewlet (with Ctrl+A for instance) in the Explorer, right-click and choose Copy Path or Copy Relative Path and then paste it yourself into a new file. Demo:

openfile paths


For how to automatically send selected (modify the variable for clipboard text) to a new file see my answer at https://stackoverflow.com/a/57612004/836330. I suppose the whole thing might be made into a macro.

Here is the macro. Using a macro extension like multi-command put this into your settings.json:

 "multiCommand.commands": [

    {
      "command": "multiCommand.getOpenFilePaths",

      "sequence": [
        "workbench.files.action.focusOpenEditorsView",
        "list.selectAll",
        "copyFilePath",               // full paths
         // "copyRelativeFilePath",   // relative paths
        "workbench.action.files.newUntitledFile",
        "editor.action.clipboardPasteAction",

        // prompt for save immediately?
        // "workbench.action.files.saveAs",
      ]
    }
  ]

and some keybinding to trigger that macro:

{
  "key": "alt+o",         // whatever keybinding you wish
  "command": "extension.multiCommand.execute",
  "args": { "command": "multiCommand.getOpenFilePaths" },
},

The Open Editors viewlet can be collapsed if you wish when you trigger the macro and it still works. Demo:

get open file paths macro

Related