How to set Title of CMD to current working Directory in Windows XP

Solution 1:

Got it to work thanks to gravvity's doskey macro. He has used && to combine the cd and title commands which works perfectly. I even made this macro load every time I use cmd by tweaking the registry.

1) I created a bat file called cmd_title.bat and it contents are

@echo off
title %cd%

2) I placed this file in the C: drive (C:\cmd_title.bat)

3) Create another batch file called cmd.bat in the C: drive with the following contents

doskey cd = cd /d $* ^&^& "C:\cmd_title.bat"
title %cd%

(the /d flag is for using cd to switch to another drive).

4) Then we open regedit and go to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor. Here there is a key called AutoRun. We modify the value of this key and set it to the location of the cmd.bat file in quotes (eg: "C:\cmd.bat").

Now cd works as we want every time we open cmd.

Basically && is used for command chaining in Windows

Solution 2:

I think that pushd and popd are much more useful than cd, and would see a lot more use if they were quicker to type. I have resolved the issues of cd vs. pushd/popd and console window directory title with the following script, which I call d.bat, which is in my path.

@ echo off
rem d.bat replaces CD, PUSHD, and POPD with one command that also changes the title
rem of the console window to tell the current directory. Invoked with no arg, the
rem title is updated. Use this after changing the directory by some other means.
rem The argument / invokes popd. Any other argument invokes pushd with that arg.

if not _%1 == _ ( 
    if _%1 == _/ (
        popd
    ) else (
        pushd %*
    )
)
title %CD%

Solution 3:

You can change the Command Prompt's title by using the title command.

You may create a batch file (say mycd.bat) containing:

title "%1"
cd  "%1"

and use it instead of "cd" :

mycd "newdir"

You can also put the .bat file in system32 if you wish it to always be available.