【问题标题】:VSCode API check if path existsVSCode API 检查路径是否存在
【发布时间】:2019-10-18 13:25:18
【问题描述】:
【问题讨论】:
标签:
visual-studio-code
vscode-extensions
【解决方案1】:
根据@realappie 对另一个答案的评论,您可以使用vscode.workspace.fs。
它没有像exists 这样的方法,但你可以使用.stat()。来自the repo的例子:
try {
await vscode.workspace.fs.stat(jsUri);
vscode.window.showTextDocument(jsUri, { viewColumn: vscode.ViewColumn.Beside });
} catch {
vscode.window.showInformationMessage(`${jsUri.toString(true)} file does *not* exist`);
}
【解决方案2】:
因为有一个内置函数,所以没有 API:
import * as fs from 'fs'; // In NodeJS: 'const fs = require('fs')'
if (fs.existsSync(path)) {
// File exists in path
}
【讨论】:
-
不确定是否仍然如此。查看新的 vscode fs API 说明 here
-