Create Directories in PowerShell: New-Item for Folders
Building folder structures is foundation work. Learn to create organized directories quickly.
How It Works
New-Item creates new files and folders. When you specify -ItemType Directory, it creates a folder. PowerShell is smart—it creates parent folders if they don't exist yet.
Instead of making folders one at a time through Windows, you can create entire structures in one command.
Code Examples
Create Single Folder
# Create a folder named "MyProject"
New-Item -ItemType Directory -Name "MyProject"
# Creates: MyProject/
Create Nested Folders
# Create deeply nested structure (PowerShell creates all folders in the path)
New-Item -ItemType Directory -Path "C:\Users\Documents\Projects\MyApp\src\config"
# Result: C:\Users\Documents\Projects\MyApp\src\config (all created)
Create Multiple Folders at Once
# Create 3 folders in one command
New-Item -ItemType Directory -Name "src", "tests", "docs"
# Creates all three:
# src/
# tests/
# docs/
Professional Project Structure
# Build a complete project layout
cd Documents
New-Item -ItemType Directory -Name "MyApp"
cd MyApp
New-Item -ItemType Directory -Name "src", "tests", "public", "config"
# Now you have:
# MyApp/
# ├── src/
# ├── tests/
# ├── public/
# └── config/
Most Used Options
- -ItemType Directory - Specifies you're creating a folder (not a file)
- -Name 'FolderName' - The name of the folder to create
- -Path 'C:\full\path' - Full path where to create the folder
- -Force - Create folder even if parent doesn't exist
The Trick: Power Usage
Create multiple folders with one command: Instead of running New-Item multiple times:
# Good - but slow
New-Item -ItemType Directory -Name "src"
New-Item -ItemType Directory -Name "tests"
New-Item -ItemType Directory -Name "docs"
# Better - one command, three folders
New-Item -ItemType Directory -Name "src", "tests", "docs"
Add -Force if you want PowerShell to create parent folders automatically if they're missing!
Learn It Through Practice
Stop reading and start practicing right now:
The interactive environment lets you type these commands and see real results immediately.
Next in PowerShell for Beginners
This is part of the PowerShell for Beginners series:
- Getting Started - Your first commands
- Command Discovery - Find what exists
- Getting Help - Understand commands
- Working with Files - Copy, move, delete
- Filtering Data - Where-Object and Select-Object
- Pipelines - Chain commands together
Related Resources
Summary
You now understand:
- How this command works
- The most common ways to use it
- One powerful trick to level up
- Where to practice hands-on
Practice these examples until they feel natural. Then tackle the next command in the series.
Ready to practice? Head to the interactive environment and try these commands yourself. That's how it sticks!
What PowerShell commands confuse you? Drop it in the comments!
Top comments (0)