file management
creating folders
computer basics
duplicate question
folder creation tutorial

How to create new folder?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

Creating a folder is one of the simplest filesystem operations, but the exact command depends on where you are working. On a desktop you usually use the file manager, while in scripts and terminals you use a command such as mkdir. The important concept is that a folder, more accurately called a directory, is just a named location in the filesystem that can contain files and other directories.

Create a Folder from the Command Line

The most direct cross-platform concept is mkdir, short for make directory. On Linux and macOS shells:

bash
mkdir reports

That creates a folder named reports in the current directory.

To create nested folders in one step, add -p.

bash
mkdir -p projects/2026/q1

On Windows Command Prompt, the command is also available as mkdir or md.

bat
mkdir reports
mkdir projects\2026\q1

This is the most scriptable way to create folders, which is why it shows up in automation, build pipelines, and deployment steps.

Create a Folder Programmatically

If you are writing code, use the language's filesystem library instead of shelling out when possible. In Python, the standard library already provides this.

python
1from pathlib import Path
2
3folder = Path("reports/2026")
4folder.mkdir(parents=True, exist_ok=True)
5print(folder.exists())

parents=True creates missing parent directories. exist_ok=True avoids an error if the folder already exists.

A comparable example in Java is Files.createDirectories.

java
1import java.io.IOException;
2import java.nio.file.Files;
3import java.nio.file.Path;
4
5public class CreateFolderExample {
6    public static void main(String[] args) throws IOException {
7        Path path = Path.of("reports", "2026");
8        Files.createDirectories(path);
9        System.out.println("Created: " + path.toAbsolutePath());
10    }
11}

That is usually better than invoking operating-system-specific commands from code.

Create a Folder in a Desktop File Manager

If you are not scripting, the graphical route is usually faster.

On Windows File Explorer:

  • open the target location
  • right-click an empty area
  • choose New and then Folder
  • type the folder name and press Enter

On macOS Finder, the common shortcut is Shift + Command + N.

On Linux desktop environments, the wording varies slightly, but file managers usually offer a New Folder action in the context menu.

Even in graphical tools, the underlying operation is the same: the operating system creates a new directory entry at the chosen path.

Naming and Path Rules Matter

Folder creation only fails for a few predictable reasons:

  • the name is invalid for the platform
  • the folder already exists and the tool does not allow duplicates
  • the parent directory does not exist
  • you do not have permission to write there

For example, Windows restricts characters such as : in file and folder names, while Unix-like systems primarily reserve the slash because it separates path components.

When writing automation, always use the path utilities from your language so separators and escaping stay correct across platforms.

Common Pitfalls

A common mistake is trying to create a nested directory without creating parents. mkdir reports/2026/q1 fails on many systems if reports/2026 does not exist yet. Use mkdir -p in the shell or the equivalent recursive directory API in code.

Another mistake is assuming a command succeeded without checking permissions. Directories under system paths or shared locations may require elevated privileges or different ownership.

Developers also sometimes concatenate path strings manually, which leads to broken separators on another operating system. Prefer pathlib, Path, or the platform-specific path utilities instead of building paths by hand.

Finally, do not confuse creating a folder with switching into it. mkdir reports creates it, while cd reports changes the shell's current directory. Those are separate operations.

Summary

  • The generic command-line tool for creating folders is mkdir.
  • Use recursive options such as -p or language APIs such as createDirectories when parents may be missing.
  • Desktop file managers provide the same operation through New Folder style actions.
  • Folder creation can fail because of invalid names, missing parents, or permission errors.
  • In code, prefer filesystem libraries over shell commands for safer cross-platform behavior.

Course illustration
Course illustration

All Rights Reserved.