Sub topic 2
Navigating and managing folders: dir, cd, md, rd
This chapter covers the four Command Prompt commands for looking at and changing the folder structure: dir, cd, md, and rd. It assumes you can open an elevated Command Prompt and read /? help, as covered in the first chapter. It also assumes you know what a drive, folder, and path are.
The working directory and paths
Command Prompt always has a current directory, also called the working directory. The prompt shows it, for example C:\Users\Sam>. Commands that take a path resolve it relative to that folder unless you give a full path.
- An absolute path starts with a drive letter or a share name, such as
C:\Windows\System32. - A relative path starts from the current folder, such as
Documents\Reports. - A single dot (
.) means the current folder. Two dots (..) mean the parent folder. - A leading backslash, as in
\Temp, means the root of the current drive.
Each drive keeps its own current directory. Typing a drive letter alone, such as D:, switches to that drive and to the folder you last used on it.
The diagram below shows how cd moves through a small folder tree.
dir: listing folder contents
dir lists the files and subfolders in a folder. With no argument it lists the current folder.
dir
dir C:\Windows
dir *.txt
dir /a
dir /s /b *.log
dir /o:dCommon switches:
| Switch | Effect |
|---|---|
| `/a` | Shows hidden and system items too. `/a:h` shows only hidden items. `/a:d` shows only directories. |
| `/s` | Searches the folder and all subfolders. |
| `/b` | Bare format: names only, with no headers or sizes. With `/s` it prints full paths. |
| `/o` | Sorts the output. `/o:n` sorts by name, `/o:s` by size, `/o:d` by date, and `/o:-d` newest first. |
| `/p` | Pauses after each screen. |
| `/q` | Shows the file owner. |
Wildcards narrow the listing. The asterisk (*) stands for any run of characters and the question mark (?) for one character. So dir *.txt lists every text file, and dir report?.docx matches report1.docx but not report10.docx.
By default dir hides files that have the hidden or system attribute. If a file seems to be missing, run dir /a before assuming it was deleted. This is a common troubleshooting step when malware or a misconfigured setting hides files.
cd: changing the current directory
cd (short for chdir) changes the working directory.
cd Documents
cd ..
cd \
cd C:\Windows\System32
cd /d D:\Backup
cd "C:\Program Files"Points to remember:
cdwith no argument prints the current directory.cd ..goes up one level.cd ..\..goes up two.cd \jumps to the root of the current drive.cddoes not change drives on its own. FromC:\,cd D:\Backupchanges the remembered folder on D: but leaves you on C:. Usecd /d D:\Backup, or typeD:first.- Paths that contain spaces need double quotes, as in
cd "C:\Program Files".
A common mistake on the exam and at the help desk is running cd D:\Data and then wondering why the prompt still shows C:. The /d switch fixes it.
md: creating folders
md (short for mkdir) creates a directory.
md Projects
md Projects\2026\Reports
md "Client Files" ArchiveCommand Prompt enables command extensions by default, so md creates every missing folder in the path. The second example builds Projects, 2026, and Reports in one step. You can list several names in one command, and names with spaces need quotes. If the folder already exists, md prints an error and changes nothing.
rd: removing folders
rd (short for rmdir) deletes a directory.
rd OldFolder
rd /s OldFolder
rd /s /q OldFolder| Form | Behavior |
|---|---|
| `rd name` | Removes the folder only if it is empty. Otherwise it fails with "The directory is not empty." |
| `rd /s name` | Removes the folder, all subfolders, and all files. It asks for confirmation. |
| `rd /s /q name` | Does the same without asking (quiet mode). |
You cannot remove the folder you are currently in, or a folder that another program has open. Move out with cd .. and close the program, then try again.
Permissions and elevation
These commands follow normal file permissions. A standard user can create folders in their own profile but not in C:\Windows or C:\Program Files. Writing there fails with "Access is denied." Opening Command Prompt as administrator lets the commands succeed where the account has the rights, but elevation does not override every protection. Files owned by TrustedInstaller, for example, may still refuse to be removed.
Putting it together
This sequence builds a folder, works inside it, checks it, and cleans up.
cd /d C:\
md Lab\Logs
cd Lab\Logs
dir
cd ..\..
rd /s /q Lab
dir /a:dIt switches to C:\, creates Lab\Logs, enters it, lists it (empty), returns to the root, deletes the whole Lab tree, and lists the remaining directories to confirm.
Common errors
- "The system cannot find the path specified" means a folder in the path does not exist, or a space was not quoted.
- "The system cannot find the file specified" from
dirmeans nothing matched the name or wildcard. - "Access is denied" means missing permissions. Try an elevated prompt, but check ownership first.
- "The directory is not empty" from
rdmeans you need/s, after you are sure you want everything gone. - "The process cannot access the file because it is being used by another process" means something has the folder open. Close it.
Exercise
You are in C:\Users\Sam and need to list every .log file under D:\Apps, including subfolders, showing only full paths. Which single command does this without changing your current directory?
Show answer
dir /s /b D:\Apps\*.log. The /s switch searches subfolders, /b prints bare full paths, and giving the full path means no cd is needed.
Exercise
You run cd D:\Data from C:\, but the prompt still shows C:\>. Why, and how do you fix it?
Show answer
cd without /d does not change the current drive. It only updates the remembered folder for D:. Run cd /d D:\Data, or type D: and press Enter.
Exercise
A folder C:\Temp\Old contains files. rd C:\Temp\Old fails. What command removes it along with its contents, and what is the risk?
Show answer
rd /s C:\Temp\Old (add /q to skip the prompt). The risk is that the deletion is permanent and bypasses the Recycle Bin, so verify the path first.