我正在编写扩展,它必须支持在用户选择的文件夹中创建新的自定义项目模板(目录结构和少数文件)。有没有办法在 vscode 中打开文件夹选择器对话框?
最佳答案
VSCode 1.17 中添加了文件对话框。见 window.showOpenDialog
和 window.showSaveDialog
.
它们似乎不会选择没有文件的文件夹,但它们确实允许多选,当然您可以只使用任何选定文件的路径名。
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);
}
});
请注意,您可能需要更新您的
package.json
文件以访问此新 API。"engines": {
"vscode": "^1.17.0"
},
关于visual-studio-code - 如何在 vscode 中打开文件夹选择器对话框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45500570/