0

I want to print the path of the file the user has right clicked. I tried like below but returns undefined.

let disposable = vscode.commands.registerCommand(
    "extension.helloWorld",
    function () {
      console.log("File path is " + vscode.Uri.fsPath)
})

I tried passing vscode.Uri as shown below however vscode is not defined as function argument.

let disposable = vscode.commands.registerCommand(
    "extension.helloWorld",
    function (vscode.Uri) {
      console.log("File path is " + vscode.Uri.fsPath)
})

Also using arrow function does not work and causes error somehow.

S.P
  • 29
  • 1
  • 9
  • 1
    You don't say how or where you are triggering your command. One of these two answers should help: https://stackoverflow.com/questions/62945928/get-focused-explorer-folder-or-file-in-an-extension-when-command-triggered-by-a/65257167#65257167 or https://stackoverflow.com/a/70307717/836330 – Mark May 17 '22 at 17:14
  • I trigger the command from context menu and this link helped: https://stackoverflow.com/questions/70303516/how-to-get-the-multi-selected-files-from-the-file-explorer-in-an-extension-comma/70307717#70307717. Thanks @Mark – S.P May 20 '22 at 10:36

0 Answers0