如何为Visual Studio代码扩展创建文件?

时间:2018-10-30 22:44:23

标签: visual-studio-code vscode-extensions

我正在尝试将文件创建为扩展程序中命令之一的一部分,但似乎无法正确处理。

let wsedit = new vscode.WorkspaceEdit();
const file_path = vscode.Uri.file(value + '/' + value + '.md');
vscode.window.showInformationMessage(file_path.toString());
wsedit.createFile(file_path, {ignoreIfExists: true});
vscode.workspace.applyEdit(wsedit);
vscode.window.showInformationMessage('Created a new file: ' value + '/' + value + '.md);

value是用户输入的字符串。代码执行了,但是据我所知,没有文件被创建。如何正确创建文件?

1 个答案:

答案 0 :(得分:2)

似乎vscode.Uri不支持相对路径(here是相应的问题)。这样说,您必须使用绝对路径。以下代码段应该可以正常工作(在使用vscode v1.30.0的Windows上进行测试)

import cv2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: DLL load failed: The specified module could not be found.