askvity

How to Create a Sub Folder in Visual Studio Code?

Published in VS Code Folder Creation 3 mins read

You can create a subfolder in Visual Studio Code by using the "New File" option and typing the desired folder path.

Creating nested folders directly within Visual Studio Code's file explorer is a straightforward process, especially when you want to create multiple levels at once. Unlike traditional file systems where you might create each folder one by one, VS Code offers a shortcut.

Method for Creating Nested Folders

Based on the provided reference, a highly efficient way to create subfolders, particularly nested ones, is by leveraging the New File command within the file explorer.

Here's how you can do it:

  1. Navigate to the desired parent location: Open the Explorer view (usually by clicking the file icon on the sidebar) and locate the folder where you want the new subfolder(s) to reside.
  2. Right-click: Right-click on the parent folder or in the empty space within that folder's file list.
  3. Select "New File": From the context menu that appears, choose the "New File" option.
  4. Type the full path: In the input box that appears, instead of just typing a file name, type the name of the first folder, followed immediately by a forward slash (/), then the name of the subfolder, another slash, and so on for any further nesting. You can optionally include the name of the file you want to create within the innermost folder at the end.

Example:

To create a folder named images inside a folder named assets, you would right-click on assets, select "New File", and type:

images/

If you also wanted to create a subfolder thumbnails inside images, you would type:

images/thumbnails/

And if you wanted to create a file logo.png inside images/thumbnails/, you would type:

images/thumbnails/logo.png

VS Code is smart enough to recognize the / as a path separator and will automatically create all the necessary parent folders (images, thumbnails) before creating the final file (logo.png). Even if you only type images/subfolder/, VS Code will create both images and subfolder.

Why This Method is Useful

This technique is particularly useful for quickly setting up complex directory structures or when you need to create a file deep within a set of folders that don't yet exist. It saves you the steps of creating each folder individually.

By using the "New File" command and specifying the path with forward slashes, you streamline the process of creating both nested folders and files within them in a single action within the VS Code file explorer.

Related Articles