Command window : change its title after changing directory ?

3 views
Skip to first unread message

R.Wieser

unread,
Jul 2, 2022, 3:24:20 PMJul 2
to
Hello all,

I would like to have the command window the name of the current folder (I
often have multiple ones open / on the taskbar). For that I've got a
command replacement like this :

doskey cd=cd /d $* ^&^& d:\owncmds\dos\SetTitle.bat

with "SetTitle.bat" being

For %%F in ("%CD%") do Set Title %%~nxF

(The "For" construct because it cannot seem to apply "~nx" on an environment
variable)

This works.


I would like to get rid of the "SetTitle" batchfile though. The problem
with that is when I replace the calling of that batchfile with its contents
(and change "%CD%" to "%%CD%%") the name of the command window will show the
folder I just left, instead of the folder I've moved into.

Does anyone have an idea how to fix this ?

Regards,
Rudy Wieser


JJ

unread,
Jul 2, 2022, 10:01:02 PMJul 2
to
Use this.

doskey cd=cd/d $* $T for /d ^%A in (.) do @title ^%~nxA

JJ

unread,
Jul 2, 2022, 10:10:42 PMJul 2
to
On Sun, 3 Jul 2022 09:00:55 +0700, JJ wrote:
>
> Use this.
>
> doskey cd=cd/d $* $T for /d ^%A in (.) do @title ^%~nxA

Apparently, DOSKEY's `$T` special code caused the macro to somehow emit an
extra ENTER key (WTH).

Replace it with `^&` instead, just like in your original code. i.e.

doskey cd=cd/d $* ^& for /d ^%A in (.) do @title ^%~nxA

R.Wieser

unread,
Jul 3, 2022, 3:53:09 AMJul 3
to
JJ,

> Use this.
>
> doskey cd=cd/d $* $T for /d ^%A in (.) do @title ^%~nxA
...
> Apparently, DOSKEY's `$T` special code caused the macro to somehow
> emit an extra ENTER key (WTH).
>
> Replace it with `^&` instead, just like in your original code. i.e.

Alas, both fail with an "~nxA was unexpected at this time."

When running that the above from within a batchfile this gets displayed :

"c:\>doskey cd=cd/d $* & for /d ~nxA"

IOW, the command partially disappears. :-|


But ... you gave me a push to try to mix-and-match stuff. :-)

It turns out that my "^$^$" can be replaced by "^$".

Your "^%A" / "^%~nxA" doesn't quite work here, so I put "%%A" / "%%~nxA"
back.

I'm not sure what the "/d" for the "for" command does here. The code works
with and without.

And the source of my problem ? My usage of "%%CD%%" - replacing it with
your "." works.


The odd thing is that I'm sure I tried that too. But looking back I tried
several ones in a test batchfile, with the old tries "neutralized" by
preceeding them with a "rem" statement. Only now I realize that the "rem"
only worked for the first part, with the part after the "^$^$" still being
executed - and throwing an error. Which threw me off.


What I ended up with and seems to work is this :

doskey cd=cd /d $* ^& for %%A in (.) do @title %%~nxA


Thanks for your help.

Regards,
Rudy Wieser


Herbert Kleebauer

unread,
Jul 3, 2022, 1:46:07 PMJul 3
to
That was discussed a few weeks ago in alt.msdos.batch.nt


set dd=cd&doskey cd=cd $* ^&call title %^%dd^%%

R.Wieser

unread,
Jul 3, 2022, 3:40:55 PMJul 3
to
Herbert,

> That was discussed a few weeks ago in alt.msdos.batch.nt

Thank you. I've taken a peek into that newsgroup and found the thread.

> set dd=cd&doskey cd=cd $* ^&call title %^%dd^%%

Hmmm... Are you sure that will work ? I mean, the "set dd=cd" part isn't
stored by doskey ...

As a check I put the above in a batchfile, ran it and than looked at the
command windows caption. It said "dd%". Also, "doskey /macros" shows
"cd=cd $* &call title dd%"

Ah, I see that "%^%dd^%%" should have been "^%%dd^%%". That fixes the
environment variable, but doesn't change the "set dd=cd" problem.

Thanks for mentioning the thread though, I'm off reading it.

Regards,
Rudy Wieser


Herbert Kleebauer

unread,
Jul 3, 2022, 5:26:33 PMJul 3
to
On 03.07.2022 21:40, R.Wieser wrote:
> Herbert,
>
>> That was discussed a few weeks ago in alt.msdos.batch.nt
>
> Thank you. I've taken a peek into that newsgroup and found the thread.
>
>> set dd=cd&doskey cd=cd $* ^&call title %^%dd^%%
>
> Hmmm... Are you sure that will work ? I mean, the "set dd=cd" part isn't
> stored by doskey ...
>
> As a check I put the above in a batchfile,

You shouldn't have done that. Just enter it at the command prompt.


Reply all
Reply to author
Forward
0 new messages