Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get project folder path in visual studio code extension

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.

enter image description here

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);

});
}
like image 486
Apple Orange Avatar asked Sep 08 '19 16:09

Apple Orange


People also ask

How do I find the path to a folder in Visual Studio?

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.

Where is VS Code extension folder?

Extensions are installed in a per user extensions folder. Depending on your platform, the location is in the following folder: Windows %USERPROFILE%\. vscode\extensions.


1 Answers

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)
like image 155
Gaetan C. Avatar answered Oct 04 '22 12:10

Gaetan C.