popdPOPD Command – Restore Directory from PUSHD Stack in Windows
Learn how to use the POPD command to return to the directory saved by PUSHD in Windows CMD. Essential for batch scripts and navigation workflows.
The POPD command is a Windows Command Prompt utility that restores the directory saved by the most recent PUSHD command. Use POPD to return to your previous directory after navigating away with PUSHD—essential for batch scripts, complex navigation workflows, and maintaining script context.
Whether you're writing batch scripts that temporarily switch directories, working with network shares that require drive letter mapping, or managing build and deployment workflows, POPD pairs with PUSHD to provide reliable directory stack navigation. IT professionals and developers rely on POPD for clean script structure and predictable return paths.
This comprehensive guide covers POPD syntax, how the directory stack works with PUSHD, practical examples, troubleshooting tips, related commands, and frequently asked questions. By the end, you'll confidently use POPD for advanced directory navigation in Windows Command Prompt and batch scripts.
What Is the POPD Command?
The POPD command (Pop Directory) is a Windows Command Prompt utility that retrieves the most recently saved directory from the stack and changes to it. POPD is the complement to PUSHD: PUSHD saves your current directory and changes to a new path; POPD restores the saved directory and removes it from the stack.
POPD 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. The directory stack is last-in-first-out (LIFO): the last directory pushed is the first popped.
Why POPD Matters for Scripts
Batch scripts often need to return to their original directory after performing operations in a subdirectory. Without POPD, you'd need to track the path manually or use CD .. repeatedly—which breaks with nested logic. POPD ensures you always return to the exact directory saved by PUSHD.
Syntax
POPD
Parameters
POPD has no parameters. It simply pops the most recent directory from the stack and changes to it.
Stack empty: If you run POPD without a prior PUSHD, you'll get an error: "The directory stack is empty."
How to Use POPD Command
Basic PUSHD/POPD Pair
C:\Users\Username> PUSHD C:\Windows\System32
C:\Windows\System32> dir
C:\Windows\System32> POPD
C:\Users\Username>
PUSHD saves and navigates; POPD returns.
Nested PUSHD/POPD
C:\> PUSHD C:\Windows
C:\Windows> PUSHD System32
C:\Windows\System32> POPD
C:\Windows> POPD
C:\>
POPD returns in reverse order—last pushed is first popped.
In Batch Scripts
@echo off
PUSHD C:\Data\Backup
echo Performing backup...
xcopy /E /I C:\Source C:\Data\Backup
POPD
echo Done.
Always pair PUSHD with POPD to return to the script's starting directory.
Common Use Cases
- Batch script return – Return to script's starting directory after subdirectory operations
- Build scripts – Switch to build dir, copy outputs, return to source
- Backup scripts – Visit backup location, perform backup, return
- Network share cleanup – POPD removes temporary drive mapping created by PUSHD for UNC paths
Tips and Best Practices
- Always pair PUSHD with POPD in scripts to avoid stack buildup
- Use POPD in error handlers to ensure cleanup even when commands fail
- Each POPD must have a corresponding PUSHD—maintain stack balance
- In nested scripts, ensure POPD runs on all code paths
Troubleshooting Common Issues
"The directory stack is empty"
You ran POPD without a prior PUSHD. Ensure each POPD has a matching PUSHD before it.
"The system cannot find the path specified"
The saved directory may have been deleted or moved. The stack stores paths; if the path no longer exists, POPD fails.
Stack imbalance
If you have more PUSHD than POPD (or vice versa), the stack will be unbalanced. Fix by ensuring matching pairs.
Related Commands
PUSHD – Save and Change Directory
PUSHD saves the current directory and changes to a new path. Pair with POPD for round-trip navigation.
CD – Change Directory
CD changes directory without saving. Use CD when you don't need to return. Use PUSHD/POPD when you need to come back.
DIR – List Directory
Use DIR to verify your location before and after POPD.
Frequently Asked Questions
What does POPD do?
POPD restores the directory saved by the most recent PUSHD command. It pops the directory from the stack and changes to it.
Do I need POPD if I use PUSHD?
Yes. PUSHD saves your directory; POPD restores it. Without POPD, you'd need to manually navigate back.
What happens if I run POPD without PUSHD?
You'll get an error: "The directory stack is empty." POPD requires a prior PUSHD.
Can I run POPD multiple times?
Yes. Each POPD pops one directory from the stack. Run POPD as many times as you ran PUSHD (in reverse order).
Does POPD work with network drives?
Yes. When PUSHD is used with a UNC path, it creates a temporary drive mapping. POPD removes that mapping when you return.
Quick Reference Card
| Command | Purpose | Example |
|---|---|---|
POPD | Return to directory saved by PUSHD | POPD |
PUSHD path | Save current dir, change to path | PUSHD C:\Windows |
PUSHD + POPD | Round-trip navigation | Pair in scripts |
Try the POPD Command in Our Simulator
Practice the POPD command safely in our Windows Command Simulator. Run PUSHD and POPD together to see the directory stack in action.
Visit the Commands Reference for a full list of supported Windows CMD commands.
Summary
The POPD command restores the directory saved by the most recent PUSHD command. Always pair PUSHD with POPD in batch scripts to maintain stack balance and ensure clean return paths. Use POPD for reliable navigation in complex workflows and scripts.