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

Jerold Schulman

May 15, 2002

1 Min Read
ITPro Today logo in a gray background | ITPro Today

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



Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like