I'm trying to make a vscode extension. One functionnality it will need is creating a new file that the user can modify and then save. I use the following code to do so :
export async function linkA() {
const newFile = Uri.parse('untitled:' + path.join(workspace.workspaceFolders![0].uri.path + "/templates", 'filename.txt'));
workspace.openTextDocument(newFile).then(async document => {
const edit = new WorkspaceEdit();
edit.insert(newFile, new Position(0, 0), "Hello world!");
return workspace.applyEdit(edit).then(success => {
if (success) {
window.showTextDocument(document);
} else {
window.showInformationMessage('Error!');
}
}); });}
When the function linkA is called, this does open a new file "filename.txt" and I can edit it. But when I try to save it I get the following error message (as a vscode information window ) : Failed to save 'filename.txt': Unable to write file '\c:\Users\RAM\Desktop\vscode-extension-samples\helloworld-sample\templates\filename.txt' (EntryNotFound (FileSystemError): Error: ENOENT: no such file or directory, open '\c:\Users\RAM\Desktop\vscode-extension-samples\helloworld-sample\templates\filename.txt').
Anybody knows how to fix this ?
Thanks