How to open folder selection dialog in vscode?

I'm writing an extension that needs to support the creation of new, custom project templates (directory structure and multiple files) in a user-selected folder. Is there a way to open the folder selection dialog in vscode?

+3


source to share


2 answers


File dialogs were added in VSCode 1.17. See window.showOpenDialog

and window.showSaveDialog

.

They don't seem to select a folder without a file, but they do allow multi-screen selection, and of course, you can just select the path to any selected file.

    const options: vscode.OpenDialogOptions = {
         canSelectMany: false,
         openLabel: 'Open',
         filters: {
            'Text files': ['txt'],
            'All files': ['*']
        }
    };

    vscode.window.showOpenDialog(options).then(fileUri => {
        if (fileUri && fileUri[0]) {
            console.log('Selected file: ' + fileUri[0].fsPath);
        }
    });

      



Note. You may need to update the file package.json

to access this new API.

"engines": {
    "vscode": "^1.17.0"
},

      

+2


source


No, but there is an open feature request for this: # 13807



+1


source







All Articles