askvity

How do I Add New Files and Folders Quickly in Visual Studio Code?

Published in VS Code File Management 4 mins read

Adding new files and organizing them into folders is a fundamental task when working on projects in Visual Studio Code. While you can always use the right-click context menu in the Explorer sidebar, VS Code offers a much faster way to create multiple new files and even new folders simultaneously using a simple input field.

Quick File and Folder Creation

Visual Studio Code provides an efficient workflow for generating new files and directories directly within the editor interface, often accessible via a keyboard shortcut or a button associated with the Explorer panel. This method allows you to define the structure of your project quickly without navigating through multiple menus.

Based on the reference provided, you can add new files and folders rapidly:

  • Adding Multiple New Files: You can type the names of the files you want to create, separated by commas. For example, typing test.Html, test.Html.Css and hitting Enter will create two new files named test.Html and test.Html.Css in the currently selected directory within the Explorer.
  • Creating a New Folder: To create a folder, simply type the desired name of the folder followed by a forward slash (/). For instance, typing scripts/ will create a new folder named scripts.
  • Combining Files and Folders: You can even create a folder and add files within it in one go by typing the folder name, a slash, and then the file name(s), e.g., scripts/main.js. You can extend this to multiple files within a new folder: assets/image.png, assets/style.css.

This streamlined approach significantly speeds up the initial setup or expansion of your project's directory structure.

Steps to Quickly Add New Files and Folders

Here's a general guide on how to use this quick creation method:

  1. Navigate to the Desired Location: In the VS Code Explorer sidebar, click on the folder where you want the new file(s) or folder(s) to be created. If you want them at the root of your project, click on the project's root folder.
  2. Activate the Input Field: Depending on your VS Code setup or theme, you might see a button (often a "New File" icon) associated with the selected folder, or a keyboard shortcut might activate the input field directly. Look for an input box that appears when you're ready to create a new item.
  3. Type Names:
    • For a single file: Type the file name (e.g., index.html).
    • For multiple files: Type file names separated by commas (e.g., styles.css, script.js).
    • For a folder: Type the folder name followed by a slash (e.g., images/).
    • For files within a new folder: Type the folder name, slash, and then the file name(s) (e.g., src/app.js, src/components/header.js).
  4. Confirm Creation: Press Enter or Return. VS Code will create the specified files and/or folders in the location you selected.

This method is particularly useful for quickly scaffolding out basic project structures or adding several related files at once.

Summary of Quick Creation Syntax

For clarity, let's summarize the syntax for quick creation:

Action Input Syntax Examples Result
Create a single file index.html Creates index.html
Create multiple files file1.txt, file2.md Creates file1.txt and file2.md
Create a single folder data/ Creates a folder named data
Create folder and file utils/helper.js Creates utils folder and helper.js inside
Create folder and multiple files styles/main.css, styles/theme.css Creates styles folder and two .css files inside

This quick method bypasses the need for multiple clicks and context menu interactions, making your workflow more efficient.

Related Articles