Display Current Folder
To check which folder you are working in from Command Prompt or a batch file, use the cd command.
This article explains how to display the current directory (working directory), the difference between %cd% and %~dp0 in batch files, and how to change to a folder on another drive.
Quick Answer
| Goal | Command |
|---|---|
| Display the current directory | cd |
| Use the current directory as a variable | %cd% |
| Get the folder where the batch file is saved | %~dp0 |
| Change to a folder on another drive | cd /d D:\work |
| Display the current directory in PowerShell | Get-Location (pwd) |
Display the Current Directory
Running cd without arguments prints the full path of the current directory.
Run from Command Prompt
Run from a batch file
@echo off
setlocal
cd
endlocal
exit
To embed the path in a string, use %cd%.
@echo off
echo Current folder: %cd%
Change the Current Directory
Pass a path to cd to change the current directory. For example, to move to the temporary folder (the %TEMP% environment variable):

中小企業経営者のためのRPA入門 RPA導入を成功させる方法

60分でわかる! AIエージェント 超 入門

コマンドラインの黒い画面が怖いんです。

知識・才能ゼロでもらく~に月10万円稼ぐ! よくわかるAI副業超入門
If the path contains spaces, enclose it in double quotes.
cd "C:\Program Files"
Use /d to Switch Drives
cd alone cannot switch to a different drive. Add the /d option to change the drive and folder at once.
Work with Files Using Relative Paths
Relative paths are based on the current directory, so your commands keep working even if the folder layout changes.
| Symbol | Meaning |
|---|---|
. | Current directory |
.. | One folder up |
As an example, move sample.txt in the current directory to the backup folder one level up.
@echo off
setlocal
set "FILE=sample.txt"
set "DEST=..\backup\"
move "%FILE%" "%DEST%"
endlocal
exit
In Batch Files, Know the Difference from %~dp0
The current directory when a batch file runs is not always the folder where the batch file is saved.
- Run from Command Prompt: the directory you were in
- Run by double-clicking: the batch file’s folder
- Run as administrator: often
C:\Windows\System32
To reliably work with files next to the batch file, use %~dp0 (the batch file’s own folder) or run cd /d "%~dp0" at the top.
@echo off
cd /d "%~dp0"
echo Folder of this batch file: %cd%
In PowerShell
PowerShell uses the Get-Location cmdlet (alias pwd) to display the current directory. cd is an alias of Set-Location and is used to change folders, not to display the path.
Get-Location
Summary
- Display the current directory with
cd; use%cd%as a variable - Use
cd /dto switch drives - Get the batch file’s own folder with
%~dp0