I am trying to get project folder path in visual studio code extension but very difficult to find the answer. My code is not working. I do not know it is possible or not. I have checked in google no one answer for this question. Anyone know about this please help me to find the answer.
extension.js:
var vscode = require("vscode");
var path = require("path");
exports.activate = context => {
const findPath =
vscode.commands.registerCommand('extension.search', () => {
let findprojectfolderPath = vscode.workspace.uri.fsPath; // Not working
console.log(findprojectfolderPath);
});
}
Did you know you can right click on the tab in the code editor window to access the file path or to open the folder in Windows Explorer? Check it out. By default, the file path for Visual Studio projects is very long.
Extensions are installed in a per user extensions folder. Depending on your platform, the location is in the following folder: Windows %USERPROFILE%\. vscode\extensions.
I would like to update Pushprajsinh Chudasama's answer as vscode.workspace.rootPath
is now deprecated. It is being replaced by vscode.workspace.workspaceFolders
which returns an array of WorkspaceFolders | undefined
. To retrieve the path to all your workspace folders, you may now use:
vscode.workspace.workspaceFolders?.map(folder => folder.uri.path)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With