Re: how do I set the window title to the current directory path?

5 views
Skip to first unread message

R.Wieser

unread,
Jul 3, 2022, 4:13:14 PMJul 3
to
crossposted to crossposted to microsoft.public.windowsxp.general

Kenny,

For some "odd reason" I had the same question but posted it into the
microsoft.public.windowsxp.general. Herbert Kleebauer alerted me to this
thread.

>>set dd=cd
>>doskey cd=cd $* ^&call title %^%dd^%%
>>
>
> Indeed it does! Kudos to you for figuring that out.

Herbert also posted your final(?) solution :

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

I think that you have found out by now that that doesn't quite work. For
multiple reasons :

Take a look at what "doskey /macros" shows you. You might notice that the
stored command replacement is this : "cd=cd $* &call title dd%". Which
ofcourse means that the title of your command window will always be "dd%"

Easy to fix, either use "^%%dd^%%" - or just "%%dd%%". ("^%dd^%" doesn't
work)

The biggest problem however is that the "set dd=cd&" part of your command
isn't stored in the doskey command replacement. Which ofcourse means that
the current directory is ony *once* stored into the "dd" variable, and than
used for all the window captions. And I don't think that is what you
want(ed). :-)

Also, IFAIKS that "call" in there is not needed.


With the help of JJ I found a solution which seems to work nicely :

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

(caveat: I did my work under XPsp3)

Regards,
Rudy Wieser


Herbert Kleebauer

unread,
Jul 3, 2022, 5:19:12 PMJul 3
to
On 03.07.2022 22:13, R.Wieser wrote:
> crossposted to crossposted to microsoft.public.windowsxp.general
>
> Kenny,
>
> For some "odd reason" I had the same question but posted it into the
> microsoft.public.windowsxp.general. Herbert Kleebauer alerted me to this
> thread.
>
>>>set dd=cd
>>>doskey cd=cd $* ^&call title %^%dd^%%
>>>
>>
>> Indeed it does! Kudos to you for figuring that out.
>
> Herbert also posted your final(?) solution :
>
>> set dd=cd&doskey cd=cd $* ^&call title %^%dd^%%
>
> I think that you have found out by now that that doesn't quite work. For
> multiple reasons :

Did you try it? Here it works.

> Take a look at what "doskey /macros" shows you. You might notice that the
> stored command replacement is this : "cd=cd $* &call title dd%". Which
> ofcourse means that the title of your command window will always be "dd%"

Here I get:

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

D:\>doskey /macros
cd=cd $* &call title %%dd%%


> Easy to fix, either use "^%%dd^%%" - or just "%%dd%%". ("^%dd^%" doesn't
> work)

The fix is the bug!

> The biggest problem however is that the "set dd=cd&" part of your command
> isn't stored in the doskey command replacement. Which ofcourse means that

It don't have to be stored in the doskey macro. It is just a one line
replacement for:

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


> the current directory is ony *once* stored into the "dd" variable, and than
> used for all the window captions. And I don't think that is what you
> want(ed). :-)

Not the current directory is stored in the variable "dd" but the
string "cd"


> Also, IFAIKS that "call" in there is not needed.

Without the call it wouldn't work.

R.Wieser

unread,
Jul 4, 2022, 3:53:35 AMJul 4
to
Herbert,

>> I think that you have found out by now that that doesn't quite work. For
>> multiple reasons :
>
> Did you try it? Here it works.

When I doubt something works I normally test it before posting about it.
As I've done this time too.

>> Easy to fix, either use "^%%dd^%%" - or just "%%dd%%". ("^%dd^%" doesn't
>> work)
>
> The fix is the bug!

You might want to explain that.

As mentioned, when I use "doskey /macros" I see that that "%^%dd^%%" has
been turned into "dd%" - which definitily doesn't give the sought-for
result.

>> The biggest problem however is that the "set dd=cd&" part of your command
>> isn't stored in the doskey command replacement. Which ofcourse means
>> that
>
> It don't have to be stored in the doskey macro. It is just a one line
> replacement for:

Yeah, you already said that. The problem is that you are not *explaining*,
nor do I see you give any test results.

> Not the current directory is stored in the variable "dd" but the string
> "cd"

Oh blimy, I overlooked that the "cd" there doesn't have "%" signs around it
(set dd=%cd%"). That makes it even worse : What you end up with is "title
cd". And at least here that "cd" there is regarded as *text*, not as a
command.

(ignore this. I now understand how your posted solution works)

>> Also, IFAIKS that "call" in there is not needed.
>
> Without the call it wouldn't work.

It does here.

Maybe you should tell us which OS you're using / that "alt.msdos.batch.nt"
newsgroup is ment for ?

AFAIKS you seem to think that the solution you posted (you got from there)
should also work under XP. And as I've been telling you, it doesn't.

>> As a check I put the above in a batchfile,
>
> You shouldn't have done that. Just enter it at the command prompt.

Ackkk.... thats quite a bit of a difference. I've just tried it that way
and it works. And now I also understand why you need that "call" in
there.

Not usefull to me though, as I have zero wish to type it in every time I
open a command window. :-(

And I would still suggest to put that "set dd=cd" part *inside* the doskey
macro - other batchfiles could overwrite the "dd" environment variable and
leave you with unexpected results.

Regards,
Rudy Wieser

P..s
I can't seem to figure out how to put more "%" / "^%" sequences around that
"%^%dd^%%" to get it to work when started from a batchfile. (yeah, I already
have a working solution. That doesn't mean I'm not interrested in other
solutions too).


Herbert Kleebauer

unread,
Jul 4, 2022, 6:52:55 AMJul 4
to
On 04.07.2022 09:53, R.Wieser wrote:

>>> As a check I put the above in a batchfile,
>>
>> You shouldn't have done that. Just enter it at the command prompt.
>
> Ackkk.... thats quite a bit of a difference. I've just tried it that way
> and it works. And now I also understand why you need that "call" in
> there.
>
> Not usefull to me though, as I have zero wish to type it in every time I
> open a command window. :-(

It is the same as like

for %i in (hello world) do echo %i

It does work on the command line but not in a batch file. If you want
to use it in a batch file, you have to add a few %:

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


> And I would still suggest to put that "set dd=cd" part *inside* the doskey
> macro - other batchfiles could overwrite the "dd" environment variable and
> leave you with unexpected results.

You can use any name which is not used by other batch code instead
of "dd". But if there is a naming conflict with an other batch, then
maybe it is better the doskey macro stops working than the other
batch stops working.

R.Wieser

unread,
Jul 4, 2022, 7:46:27 AMJul 4
to
Herbert,

> It does work on the command line but not in a batch file. If you want
> to use it in a batch file, you have to add a few %:

I know. I just didn't get it to work.

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

And as is appears now I was just too focussed on keeping those "^" in there.
You /said/ they where part of the solution. :-)

> You can use any name which is not used by other batch code instead of
> "dd".

I've got another solution - not using an environment variable :

You could use my origional solution (from before you posted, with the "for
%%A" in it) and remove the "~nx" part. The below also works :

(from within a batchfile)

doskey cd=echo off^&cd $*$Ttitle %%cd%%^&echo on

The trick is that the "$T" in there takes the place of the "call", but also
delays the expansion of the %CD% variable. The "echo off" and "echo on"
parts are needed because "$T" displays another prompt.

Thanks for your responses. I had some fun trying the different
possibilities out.

Regards,
Rudy Wieser

P.s.
I still like my solution which only displays the last folders name best
though. :-)


Kenny McCormack

unread,
Jul 4, 2022, 8:08:17 AMJul 4
to
In article <t9st8l$1pl8$1...@gioia.aioe.org>,
R.Wieser <add...@not.available> wrote:
>crossposted to crossposted to microsoft.public.windowsxp.general
>
>Kenny,
>
>For some "odd reason" I had the same question but posted it into the
>microsoft.public.windowsxp.general. Herbert Kleebauer alerted me to this
>thread.

Keep in mind that most of what you attribute to me (as in, "Your (Kenny's)
code, blah, blah, blah") is not mine at all. Most of it was dreamed up,
composed, and posted by Herbert. So, credit where credit is due.

In particular, if you see code that omits the space after the &, that's a
Herbert trademark.

N.B. I'm not saying it is wrong. In fact, it is quite right to do that.
But most code that I wrote won't have it.

Just tryin' to help you do your archaeology...

--
There are many self-professed Christians who seem to think that because
they believe in Jesus' sacrifice they can reject Jesus' teachings about
how we should treat others. In this country, they show that they reject
Jesus' teachings by voting for Republicans.

R.Wieser

unread,
Jul 4, 2022, 8:22:45 AMJul 4
to
Kenny,

> Keep in mind that most of what you attribute to me (as in, "Your (Kenny's)
> code, blah, blah, blah") is not mine at all. Most of it was dreamed up,
> composed, and posted by Herbert. So, credit where credit is due.

My apologies to both of you. I thought it was you who put it together with
Herbert commenting upon it.

Regards,
Rudy Wieser


R.Wieser

unread,
Jul 4, 2022, 8:22:45 AMJul 4
to
Herbert,

I wrote :

>> And as is appears now I was just too focussed on keeping those "^" in
>> there. You /said/ they where part of the solution. :-)

I got a brainfart and thought of something else to try :

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

(see the environment variable at the end)

It also works, and is easier to read & convert to in-batchfile usage.

Regards,
Rudy Wieser


Kenny McCormack

unread,
Jul 4, 2022, 9:40:52 AMJul 4
to
In article <t9um2g$1vjc$1...@gioia.aioe.org>,
Actually, some other poster originally asked the question, then I suggested
a partial solution that almost works, but I conceded that it did not work 100%
and I didn't care to spend any more time on it. Herbert then picked it up
and ran with it from there.

--
There are a lot of Wisconsin farmers right now who, despite having
themselves voted for Trump, are now wishing that their state's electors
had had the good sense to vote for the other candidate - thereby saving
them from their current predicament.

R.Wieser

unread,
Jul 4, 2022, 9:43:22 AMJul 4
to
Herbert,

I wrote :

> I got a brainfart and thought of something else to try :

Got another one : no intermediate environment variable and, IMHO, even
easier to work with :

set doskey cd=cd $* ^&call title %%c^^d%%

(from within a batchfile)

... I must have /way/ to much time on my hands.

Regards,
Rudy Wieser


Kenny McCormack

unread,
Jul 4, 2022, 9:49:00 AMJul 4
to
In article <t9uqpm$5eb$1...@gioia.aioe.org>,
Sounds like it. Sounds like you lead a happy life.
Congrats.

--
He must be a Muslim. He's got three wives and he doesn't drink.

Herbert Kleebauer

unread,
Jul 4, 2022, 11:50:34 AMJul 4
to
On 04.07.2022 15:43, R.Wieser wrote:

> Got another one : no intermediate environment variable and, IMHO, even
> easier to work with :
>
> set doskey cd=cd $* ^&call title %%c^^d%%
>
> (from within a batchfile)

That is a good one. For me batch programming is "trial and error"
and I would have never found this solution.

R.Wieser

unread,
Jul 4, 2022, 2:02:02 PMJul 4
to
Herbert,

> That is a good one. For me batch programming is "trial and error" and I
> would have never found this solution.

Although I know know a few things about batch programming, new areas are
mostly "trial and error" to me, just like for you.

It just struck me that if a "^" (escape char) could be used to tinker around
with the "%" and "&" marks like you did that there would be a possibility
that it would also work when applied to the environment variable. And as
the reason for the "dd" variable was to keep the "%cd%" variable from being
resolved too early it was a short step to putting enough "^" markers next to
the "cd" chars themselves to keep them from the "%cd% sequence being
recognised until the last step. Putting those "^" between the "c" and "d"
just made the whole string look balanced / nice.

Yep, a lot of "trial and error" I'm afraid. I've now got a batchfile with
over 10 attempts (the ones I cared to keep. Must have gone thru over 20 of
them - including ones with "echo" instead of "title") that all failed in
different ways. :-)

Regards,
Rudy Wieser


R.Wieser

unread,
Jul 5, 2022, 3:37:48 AMJul 5
to
Herbert,

> set doskey cd=cd $* ^&call title %%c^^d%%
>
> (from the within a batchfile)

This morning I woke up with a "I /have/ too look into that" thought : the
above can be interfered with.

Just type "set c^^d=foobar" on the commandline, and that "foobar" will be
all the caption you get.

IOW, trying to hide an evironment variables name isn't foolproof.

... even when I sleep I seem to have too much time on my hands. :-)

Regards,
Rudy Wieser


Reply all
Reply to author
Forward
0 new messages