Skip navigation

JSI Tip 5316. How do I get a batch file to display the current directory in the Title bar?

The Start command can be used to give a CMD Window an initial title.

To change the title in a CMD session, you can use the TITLE command. The syntax is:

TITLE string

In tip 4603, I described how to set the CurDir environment variable to the current directory by using the following statement:

for /f "Tokens=*" %%i in ('CD') do set CurDir=%%i

Here is a demonstration batch that displays the current directory in the Title bar of a CMD Window:

@echo off
@echo The title will change to %SystemRoot% in 10 seconds
@ping -n 11 127.0.0.1>nul
CD /d %SystemRoot%
for /f "Tokens=*" %%i in ('CD') do set CurDir=%%i
title %CurDir%
@echo The title will change to %userprofile%\my documents in 10 seconds
@ping -n 11 127.0.0.1>nul
pushd "%userprofile%\my documents"
title %userprofile%\my documents
@echo The title will change to %SystemRoot% in 10 seconds
@ping -n 11 127.0.0.1>nul
popd
for /f "Tokens=*" %%i in ('CD') do set CurDir=%%i
title %CurDir%
@echo The batch will end in 10 seconds
@ping -n 11 127.0.0.1>nul



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish