Display Current Folder

Maintained on

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

GoalCommand
Display the current directorycd
Use the current directory as a variable%cd%
Get the folder where the batch file is saved%~dp0
Change to a folder on another drivecd /d D:\work
Display the current directory in PowerShellGet-Location (pwd)

Display the Current Directory

Running cd without arguments prints the full path of the current directory.

Run from Command Prompt

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>cd
C:\Users\user
C:\users\user>

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):

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>cd %TEMP%
おすすめ書籍※ 広告を含む場合があります
中小企業経営者のためのRPA入門 RPA導入を成功させる方法

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

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

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

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

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

知識・才能ゼロでもらく~に月10万円稼ぐ! よくわかる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.

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>cd /d D:\work

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.

SymbolMeaning
.Current directory
..One folder up

As an example, move sample.txt in the current directory to the backup folder one level up.

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>move sample.txt ..\backup\
@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 /d to switch drives
  • Get the batch file’s own folder with %~dp0
#PowerShell #Command Prompt #Batch File