How to open folder selection dialog in vscode?
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 to share