Mindfulness

Get the Working Directory in Command Prompt (Windows)

Updated · By the Relaxmid editors

Reading time
4 min
Sections
6
Topic
Mindfulness

Type cd on its own, with no space or argument after it, and press Enter. Command Prompt prints the full path of the folder you are currently in, such as C:\Users\Sam\Documents. The prompt itself also shows a shortened form of that path before the > symbol, so you can often read it without running anything.

Read the Prompt, Then Run cd to Confirm

Every line in Command Prompt begins with something like C:\Users\Sam>. That is the current working directory, also called the current folder. Windows usually shortens it, though. If you are deep inside folders, the prompt may show C:\Users\Sam\Documents\...\Reports> with the middle replaced by three dots. That is why the cd command exists: it always prints the complete, unshortened path.

To use it:

  1. Open Command Prompt (press the Start button, type cmd, and choose Command Prompt).
  2. Type cd and press Enter. Nothing else on the line.
  3. Read the path that appears on the next line. That is your working directory.

There is a second command that does the same job: echo %cd%. It prints the same path by asking Windows to expand the built-in %cd% variable. Use whichever you find easier to remember; the output is identical.

Understand What the Working Directory Actually Changes

The working directory is where Command Prompt looks for files when you give a bare name. If your working directory is C:\Users\Sam\Documents and you type dir notes.txt, Windows looks for notes.txt inside Documents. The same file name typed from a different working directory would give “File Not Found”.

Commands that create files behave the same way. A command that writes output.txt without a full path puts that file in the working directory. Knowing the working directory before you run a command tells you where new files will land, which saves hunting for them afterwards.

Changing the working directory is also done with cd, just with an argument. cd Documents moves into the Documents subfolder. cd .. moves up one level. cd C:\Users\Sam\Pictures jumps straight to that full path. The command with no argument is the only version that prints the path instead of changing it, so the empty form is your “where am I” question.

Spot the Difference Between the Two Directory Commands

A common mix-up: cd and dir look similar but answer different questions. cd with no argument answers “which folder am I in?”. dir answers “what is inside this folder?”. If you want both pieces of information, run cd first, then dir.

Another mix-up involves PowerShell, which is a different program that looks almost identical. In PowerShell, cd on its own does nothing; the equivalent command is Get-Location, often shortened to pwd. If typing cd gives no output at all, check the window title: it probably says “Windows PowerShell” rather than “Command Prompt”. Both pwd and Get-Location work there.

Why the prompt sometimes shows a short path

When the full path would make the line too long, Windows replaces the middle of it with three dots. The cd command never shortens anything, so it is the reliable way to see the true path. Copy it directly from the cd output if you need to paste it somewhere.

Work Through a Real Example

Suppose you open Command Prompt and see this prompt:

C:\Users\Sam>

You run cd Documents, then cd Reports, then cd. The output reads:

C:\Users\Sam\Documents\Reports

You now know three things at once: your working directory, the folder where any file you create will be saved, and the path you would need to type to return here later. To get back to the top, run cd C:\Users\Sam or type cd .. twice, once per folder level. Each cd .. climbs exactly one level, so two levels need two commands.

If a path contains spaces, such as Program Files, wrap it in double quotes when you change to it: cd "C:\Program Files". The quotes are not needed for reading the directory with plain cd, only for moving into names that contain spaces.

Fix the Cases Where the Path Looks Wrong

Sometimes cd prints a path that starts with a different drive letter, such as D:\ instead of C:\. This happens because each drive keeps its own working directory. Typing D: switches to the D drive and returns you to whatever folder you last used there, not to its root. To jump to a specific folder on another drive in one step, type cd /d D:\Data. The /d part tells cd to change drives as well as folders.

If the output shows a path you did not expect, it usually means a previous command changed the directory and you did not notice. Running cd before each important command is a simple habit that keeps you oriented, especially in longer sessions.

Can the working directory be copied to the clipboard?

Yes. Run cd | clip and the path is copied to the clipboard with no printed output. Paste it anywhere with Ctrl+V. The clip command sends whatever it receives to the clipboard, so it also works with other commands’ output.

Does this work in the Terminal app?

Yes. Windows Terminal can host Command Prompt as one of its tabs, and cd behaves the same there. If the tab is running PowerShell instead, use pwd. The tab title or the prompt style tells you which shell you are in.

Related

General information for everyday wellbeing, not medical advice. If something affects your health, sleep or mood for more than a short while, talk to a qualified professional. Read more

Spotted an error? Tell us and we will correct it (corrections policy).