cd & dir
Two commands do most of the moving around in CMD: cd (change directory) shows or changes the current folder, and dir lists what is in a folder. Every relative path you use is resolved from the current folder, which the prompt always shows.
Where am I? cd without arguments
cd on its own prints the current folder. Inside scripts, the variable %cd% holds the same value:
@echo off
cd
echo The current folder is %cd%C:\Users\learner
The current folder is C:\Users\learner
The examples on this site start in the home folder of the user learner. On your PC, a new Command Prompt usually starts in your own home folder, C:\Users\<your name>. The long name chdir is an alias of cd.
Changing folders
| Command | Goes to |
|---|---|
cd Documents |
the subfolder Documents of the current folder (relative path) |
cd C:\Windows\System32 |
that exact folder (absolute path) |
cd .. |
the parent folder |
cd ..\.. |
two levels up |
cd \ |
the root of the current drive, C:\ |
cd "My Projects" |
a folder with a space in its name (quotes) |
@echo off
mkdir demo\site\css
cd demo\site\css
cd
cd ..
cd
cd ..\..
cd
cd \
cdC:\Users\learner\demo\site\css
C:\Users\learner\demo\site
C:\Users\learner
C:\
mkdir created all three nested folders at once (next lesson). . means "this folder" and .. means "the parent folder"; both work in any path, e.g. ..\images\logo.png.
Tip: Press Tab while typing a path at the prompt and CMD completes the folder or file name. Press Tab again to cycle through other matches.
Drives and cd /d
Every drive (C:, D:, a USB stick, a network drive) has its own current folder. Typing a drive letter and colon switches to that drive. A plain cd D:\Data changes D:'s current folder but leaves you on C:, which surprises everyone the first time. Use cd /d to change drive and folder together:
C:\Users\ada>cd D:\Data
C:\Users\ada>D:
D:\Data>cd /d C:\Windows
C:\Windows>Scripts should always use cd /d "%~dp0" (go to the script's own folder) rather than plain cd.
pushd and popd
pushd changes to a folder and remembers where you were; popd goes back. They can be nested like a stack, and pushd also changes the drive:
@echo off
mkdir demo\logs
cd demo
echo start: %cd%
pushd logs
echo inside: %cd%
pushd C:\tad
echo deeper: %cd%
popd
echo back: %cd%
popd
echo home again: %cd%start: C:\Users\learner\demo
inside: C:\Users\learner\demo\logs
deeper: C:\tad
back: C:\Users\learner\demo\logs
home again: C:\Users\learner\demo
pushd \\server\share even maps a temporary drive letter for a network folder, which plain cd can't open.
dir: listing a folder
dir without switches prints a detailed listing: the volume, the folder, each entry with date, time, <DIR> or size, and a summary. This is a sample from a real Windows 11 PC (dates, sizes and the serial number on yours will differ):
C:\Users\ada\Projects>dir
Volume in drive C has no label.
Volume Serial Number is 6A2E-91F4
Directory of C:\Users\ada\Projects
10/17/2026 09:12 AM <DIR> .
10/17/2026 09:12 AM <DIR> ..
10/16/2026 04:45 PM 1,284 notes.txt
10/17/2026 08:30 AM <DIR> photos
10/02/2026 11:07 AM 48,213 report.docx
09/28/2026 02:15 PM 356 todo.txt
3 File(s) 49,853 bytes
3 Dir(s) 212,447,662,080 bytes freeThe date and time format follows your Windows region settings. The entries . and .. are the folder itself and its parent.
Useful dir switches
| Switch | Meaning |
|---|---|
/b |
bare format: names only, perfect for scripts |
/s |
include all subfolders (with /b, prints full paths) |
/a:d / /a:-d |
only directories / only files |
/a:h |
hidden files (dir /a shows everything) |
/o:n /o:-n |
order by name / reverse name |
/o:s /o:d /o:e |
order by size / date / extension |
/o:g |
group directories first |
/w |
wide format, several names per line |
/p |
pause after each screenful |
/q |
show the owner of each file |
/t:c /t:w |
show creation time / last write time (default) |
The examples on this site use dir /b /o:n: bare names in name order, so the output is the same on every computer.
@echo off
mkdir demo\img & cd demo
echo body{}> style.css
echo ^<h1^>Hi^</h1^>> index.html
echo ^<h1^>About^</h1^>> about.html
echo png> img\logo.png
echo --- all entries:
dir /b /o:n
echo --- only .html files:
dir /b /o:n *.html
echo --- everything, recursively:
dir /b /o:n /s--- all entries:
about.html
img
index.html
style.css
--- only .html files:
about.html
index.html
--- everything, recursively:
C:\Users\learner\demo\about.html
C:\Users\learner\demo\img
C:\Users\learner\demo\index.html
C:\Users\learner\demo\style.css
C:\Users\learner\demo\img\logo.png
dir /s lists the folder's own entries first, then walks into each subfolder.
Wildcards
* matches any number of characters and ? matches exactly one. They work in dir, copy, del, move, ren and most other file commands:
@echo off
mkdir demo & cd demo
for %%n in (data1.csv data2.csv data10.csv notes.txt readme.md) do echo x> %%n
echo --- data?.csv
dir /b /o:n data?.csv
echo --- data*.csv
dir /b /o:n data*.csv
echo --- notes.* (any extension)
dir /b /o:n notes.*--- data?.csv
data1.csv
data2.csv
--- data*.csv
data1.csv
data10.csv
data2.csv
--- notes.* (any extension)
notes.txt
Notice that /o:n sorts names as text: data10.csv comes before data2.csv. (File Explorer uses "natural" order instead.)
Learn more: Navigating Folders · Listing Files · Bash cd & pwd
Test yourself
You are on drive C:. Which command switches to D:\Data in one step?
- cd D:\Data
- cd /d D:\Data
- chdir D:
- goto D:\Data
Which command lists only file names, including those in subfolders?
- dir /w
- dir /b /s
- dir /p
- dir /q
What does popd do?
- Deletes the current folder
- Returns to the folder saved by the last pushd
- Goes to the parent folder
- Prints the folder stack