on-internet
← Community

How to programmatically create a file and write content using VS Code Extension API in TypeScript?

Stack Overflow ·

I am building a VS Code extension that automatically generates workspace files. I want to create a new file at a specific path inside the user's open workspace and insert generated text content into it. I tried using Node's fs.writeFileSync, but it doesn't always refresh the VS Code Explorer UI immediately. I want to use the native VS Code API (vscode.workspace.fs). Here is my current approach: import * as vscode from 'vscode'; export async function createFile(fileName: string, content: string) { const workspaceFolders = vscode.workspace.workspaceFolders; if (!workspaceFolders) { vscode.window

Comments

Sign in or sign up to comment and upvote.

No comments yet.