CMD Simulator
File Managementpushd

PUSHD Command – Save and Change Directory with Directory Stack in Windows

Learn how to use the PUSHD command to save your current directory and navigate to a new path in Windows CMD. Essential for batch scripts and complex navigation workflows.

Rojan Acharya··Updated Mar 17, 2026
Share

The PUSHD command is a Windows Command Prompt utility that saves the current directory to an internal stack and then changes to the specified path. Use PUSHD with a path to navigate while preserving your location; pair with POPD to return to the saved directory—essential for batch scripts, complex navigation workflows, and temporary directory switches.

Whether you're writing batch scripts that need to visit multiple directories and return, working with network shares that require drive letter mapping, or managing complex build and deployment workflows, PUSHD and POPD provide a robust directory stack that CD alone cannot offer. IT professionals and developers rely on PUSHD for script reliability and clean navigation patterns.

This comprehensive guide covers PUSHD syntax, how the directory stack works, practical examples for common scenarios, troubleshooting tips, related commands like POPD and CD, and frequently asked questions. By the end, you'll confidently use PUSHD for advanced directory navigation in Windows Command Prompt and batch scripts.

What Is the PUSHD Command?

The PUSHD command (Push Directory) is a Windows Command Prompt utility that implements a directory stack—a last-in-first-out (LIFO) structure that stores directory paths. When you run PUSHD with a path, it pushes your current directory onto the stack and then changes to the specified directory. The complementary POPD command pops the most recently saved directory from the stack and changes to it.

PUSHD works in Command Prompt (CMD), Windows PowerShell (with CMD compatibility), Windows Terminal, and is available in all modern Windows versions including Windows 11, Windows 10, Windows 8, and Windows Server editions. Unlike CD, which only changes directory without memory, PUSHD remembers where you were so you can return later.

Why PUSHD Matters for Scripts

Batch scripts often need to:

  • Navigate to a subdirectory, perform operations, then return
  • Temporarily switch to a network share or UNC path
  • Work in multiple directories within a single script
  • Maintain script context across complex operations

PUSHD/POPD pairs ensure you always return to the correct location, even if the script fails or encounters errors—unlike manual CD .. chains that can break with nested logic.

Syntax

PUSHD [path]

Parameters

ParameterDescription
pathThe directory path to change to (absolute or relative). Can be a local path, UNC path, or network share.

No parameters: PUSHD without arguments displays an error. A path is required.

UNC paths: PUSHD automatically creates a temporary drive letter when given a UNC path (e.g., \\server\share), making it easier to work with network locations.

How to Use PUSHD Command

Basic PUSHD Usage

Save the current directory and change to a new location:

PUSHD C:\Windows\System32

Your current directory (e.g., C:\Users\Username) is pushed onto the stack. You are now in C:\Windows\System32. Run POPD to return.

Nested PUSHD Calls

You can nest PUSHD calls. Each PUSHD adds to the stack; each POPD removes from the stack:

C:\> PUSHD C:\Windows
C:\Windows> PUSHD System32
C:\Windows\System32> POPD
C:\Windows> POPD
C:\>

Use with Relative Paths

PUSHD ..

Pushes current directory and moves to parent. Useful in scripts.

Network UNC Paths

PUSHD \\server\share\folder

PUSHD creates a temporary drive letter for the UNC path, making it easier to work with network shares. POPD removes the mapping when you return.

Common Use Cases

  1. Batch script operations – Navigate to a subdirectory, run commands, return to original location
  2. Build scripts – Switch to build output directory, run build, return to source
  3. Backup scripts – Visit multiple directories, perform backup, return
  4. Network share access – Temporarily map and work with UNC paths
  5. Deployment scripts – Switch to deployment target, copy files, return

Tips and Best Practices

  • Always pair PUSHD with POPD in scripts to avoid stack buildup
  • Use PUSHD for temporary directory switches; use CD for permanent navigation
  • In batch scripts, consider error handling: if a command fails, POPD might not execute
  • PUSHD with UNC paths automatically creates drive letters—no need for NET USE in many cases

Troubleshooting Common Issues

"The directory stack is empty" (POPD without prior PUSHD)

Ensure you've run PUSHD before POPD. Each POPD must have a corresponding PUSHD.

"The system cannot find the path specified"

Verify the path exists and you have read permissions. For UNC paths, ensure network connectivity.

Stack imbalance in scripts

If your script has conditional logic, ensure every PUSHD has a matching POPD on all code paths.

Related Commands

POPD – Restore Directory

POPD is the complement to PUSHD. It pops the most recently saved directory from the stack and changes to it.

CD – Change Directory

CD changes directory without saving. Use CD when you don't need to return. Use PUSHD when you need to come back.

SUBST – Virtual Drives

SUBST creates persistent drive letter mappings. PUSHD creates temporary mappings for UNC paths.

Frequently Asked Questions

What does PUSHD do?

PUSHD saves your current directory to an internal stack and changes to the specified path. Use POPD to return to the saved directory.

How do I return after PUSHD?

Run POPD to return to the directory you were in before PUSHD. POPD pops the most recent entry from the stack.

Can I use PUSHD with network paths?

Yes. PUSHD with a UNC path (e.g., \\server\share) automatically creates a temporary drive letter, making it easier to work with network shares.

What happens if I run POPD without PUSHD?

You'll get an error: "The directory stack is empty." POPD requires a prior PUSHD to have saved a directory.

Can I nest PUSHD calls?

Yes. Each PUSHD adds to the stack. POPD returns in reverse order—last pushed is first popped.

Quick Reference Card

CommandPurposeExample
PUSHD pathSave current dir, change to pathPUSHD C:\Windows
POPDReturn to saved directoryPOPD
PUSHD ..Save and move to parentPUSHD ..
PUSHD \\server\shareMap UNC and change to itPUSHD \\server\data

Try the PUSHD Command in Our Simulator

Practice the PUSHD command safely in our Windows Command Simulator. No installation required—run PUSHD, POPD, and other examples in your browser.

Visit the Commands Reference for a full list of supported Windows CMD commands.

Summary

The PUSHD command saves your current directory to a stack and changes to a new path. Pair it with POPD to return to the saved location. Use PUSHD for batch scripts that need temporary directory switches, network share access, or complex navigation workflows. Always ensure each PUSHD has a matching POPD to maintain stack balance.