'How can I get the filepath of the right clicked item in VSCode extension?

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.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source