Discussion:
how do I set the window title to the current directory path?
(too old to reply)
Dallas
2022-04-14 15:44:37 UTC
Permalink
In a cmd.exe shell session how do I set the window title to the current directory path?
John Gray
2022-04-14 16:18:18 UTC
Permalink
Post by Dallas
In a cmd.exe shell session how do I set the window title to the current directory path?
title %cd%
Dallas
2022-04-14 16:26:02 UTC
Permalink
Post by John Gray
Post by Dallas
In a cmd.exe shell session how do I set the window title to the current directory path?
title %cd%
Thanks! Earlier I tried looking at the output of the SET command, but it turns out that %CD% is
not listed by SET.

Now I want to know what else the SET command does not disclose.
JJ
2022-04-15 10:59:22 UTC
Permalink
Post by Dallas
Post by John Gray
Post by Dallas
In a cmd.exe shell session how do I set the window title to the current directory path?
title %cd%
Thanks! Earlier I tried looking at the output of the SET command, but it turns out that %CD% is
not listed by SET.
Now I want to know what else the SET command does not disclose.
They're mostly listed in the end of SET's help. Type: set /?

To display undocumented internal variables, type: set;
The variable names starts with: =
Dallas
2022-04-15 12:44:05 UTC
Permalink
Post by JJ
Post by Dallas
Now I want to know what else the SET command does not disclose.
They're mostly listed in the end of SET's help. Type: set /?
To display undocumented internal variables, type: set;
The variable names starts with: =
Thanks!

set /? | findstr "^%"

set; | findstr "^="
Dallas
2022-04-14 16:44:34 UTC
Permalink
Post by John Gray
Post by Dallas
In a cmd.exe shell session how do I set the window title to the current directory path?
title %cd%
Now, how do I get rid of that "Administrator: " prefix in the window title and still run as
administrator?
John Gray
2022-04-14 17:16:02 UTC
Permalink
Post by John Gray
Post by Dallas
In a cmd.exe shell session how do I set the window title to the current directory path?
title %cd%
Now, how do I get rid of that "Administrator: " prefix in the window title and still run as
administrator?
For assorted built-in environment variables, see https://ss64.com/nt/syntax-variables.html
I don't think it is possible to remove the "Administrator: " prefix from the window title; someone may know a way.
Dallas
2022-04-14 19:21:14 UTC
Permalink
Post by John Gray
I don't think it is possible to remove the "Administrator: " prefix from the window title; someone may know a way.
I suppose now I need to re-think why I like to run as administrator.
Ammammata
2022-05-02 13:26:21 UTC
Permalink
Il giorno Thu 14 Apr 2022 06:18:18p, *John Gray* ha inviato su
Post by John Gray
Post by Dallas
In a cmd.exe shell session how do I set the window title to the current directory path?
title %cd%
it works, but when I change folder it does not update
--
/-\ /\/\ /\/\ /-\ /\/\ /\/\ /-\ T /-\
-=- -=- -=- -=- -=- -=- -=- -=- - -=-
........... [ al lavoro ] ...........
Kenny McCormack
2022-05-03 02:03:15 UTC
Permalink
Post by Ammammata
Il giorno Thu 14 Apr 2022 06:18:18p, *John Gray* ha inviato su
Post by John Gray
Post by Dallas
In a cmd.exe shell session how do I set the window title to the current directory path?
title %cd%
it works, but when I change folder it does not update
One way or the other, you will need to alias your "cd" command, so that
whenever you change directories, it runs the above "title" command for you.

I tried to do it with "doskey", like this:

doskey cd=cd $* ^& title ^%cd^%

and it almost worked, except that %cd% gets expanded before the "cd"
command executes, so it is out of date. It seems like the delayedexpansion
thing would fix this, but I found out that delayedexpansion only works in
batch files; it doesn't work at the prompt. And, of course, doskey macros
are command line things, not really batch files. It would be nice if there
was a way of making DOSKEY aliases that span multiple lines, instead of
having to slog everything together with &s.

I think it could be done with an actual batch file, but I lost interest in
pursuing it any further...
--
They say that Trump is a stupid man's idea of a clever man, a poor man's
idea of a rich man, and a weak man's idea of a strong man.

Well, Melania is an unclassy man's idea of classy.
Herbert Kleebauer
2022-05-03 14:49:24 UTC
Permalink
Post by Kenny McCormack
Post by Ammammata
Post by John Gray
Post by Dallas
In a cmd.exe shell session how do I set the window title to the
current directory path?
title %cd%
it works, but when I change folder it does not update
One way or the other, you will need to alias your "cd" command, so that
whenever you change directories, it runs the above "title" command for you.
doskey cd=cd $* ^& title ^%cd^%
and it almost worked, except that %cd% gets expanded before the "cd"
command executes, so it is out of date.
I don't know anything about doskey so I just randomly
inserted % and ^ in your doskey command and this works
here (but don't understand why).

set dd=cd
doskey cd=cd $* ^&call title %^%dd^%%
Kenny McCormack
2022-05-03 15:30:16 UTC
Permalink
In article <t4rfdk$p24$***@gioia.aioe.org>,
Herbert Kleebauer <***@unibwm.de> wrote:
...
Post by Herbert Kleebauer
Post by Kenny McCormack
doskey cd=cd $* ^& title ^%cd^%
and it almost worked, except that %cd% gets expanded before the "cd"
command executes, so it is out of date.
I don't know anything about doskey so I just randomly
inserted % and ^ in your doskey command and this works
here (but don't understand why).
set dd=cd
doskey cd=cd $* ^&call title %^%dd^%%
Indeed it does! Kudos to you for figuring that out.

I suppose this is one of those things where figuring out how to do it is
the first step and then figuring out why it works is the next step.

I wonder if it has something to do with the fact that %cd% isn't really a
normal variable; it is what you might call a "pseudo-variable". Somehow,
that causes it to be evaluated differently. And, somehow, when you put in
"dd" in place of "cd", it causes it to go back to the regular evaluation rules.

Anyway, as far as DOSKEY goes, all I know, I got from doing: doskey /?
It is pretty murky stuff. The fact that the parameters are referenced with
a $ sign (like in Unix), rather than with % (like in regular batch files)
always trips me up.

Final question: Just out of curiosity, why do you omit the usual space
after the & in your rendition of the doskey command? I know it doesn't
matter, but it seem "ugly" that way. I've noticed that you've done this in
the past as well (in prior postings to this ng).
--
I've learned that people will forget what you said, people will forget
what you did, but people will never forget how you made them feel.

- Maya Angelou -
Herbert Kleebauer
2022-05-03 16:43:21 UTC
Permalink
Post by Kenny McCormack
Post by Herbert Kleebauer
set dd=cd
doskey cd=cd $* ^&call title %^%dd^%%
Final question: Just out of curiosity, why do you omit the usual space
after the & in your rendition of the doskey command? I know it doesn't
matter, but it seem "ugly" that way. I've noticed that you've done this in
the past as well (in prior postings to this ng).
After the & starts a new command and because I don't insert a
space before a command at the CMD prompt I also don't insert
a space before the command after an &.

But more important is the space before the &. You can write
the two commands above in one line:

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

But if you insert a space before the & it doesn't work
anymore:

set dd=cd &doskey cd=cd $* ^&call title %^%dd^%%
Kenny McCormack
2022-05-03 18:15:45 UTC
Permalink
Post by Herbert Kleebauer
Post by Kenny McCormack
Post by Herbert Kleebauer
set dd=cd
doskey cd=cd $* ^&call title %^%dd^%%
Final question: Just out of curiosity, why do you omit the usual space
after the & in your rendition of the doskey command? I know it doesn't
matter, but it seem "ugly" that way. I've noticed that you've done this in
the past as well (in prior postings to this ng).
After the & starts a new command and because I don't insert a
space before a command at the CMD prompt I also don't insert
a space before the command after an &.
But more important is the space before the &. You can write
set dd=cd&doskey cd=cd $* ^&call title %^%dd^%%
But if you insert a space before the & it doesn't work
set dd=cd &doskey cd=cd $* ^&call title %^%dd^%%
Yup. All true.

Ain't DOS batch a fine programming langauge???
--
If you don't have faith, it's because you are reading the Bible with an
honest, truthful, real-answer seeking heart.

- Rick C Hodgin -
R.Wieser
2022-07-08 08:41:22 UTC
Permalink
Herbert,
Post by Herbert Kleebauer
set dd=cd&doskey cd=cd $* ^&call title %^%dd^%%
But if you insert a space before the & it doesn't work
set dd=cd &doskey cd=cd $* ^&call title %^%dd^%%
Thats explainable : "set" takes *everything* from the "=" upto the end of
the line and puts it into the variable (when using an "&" that becomes "the
end of the line")

set foo=the quick brown fox
echo %foo%

now try this :
- - - - - - - - - - - -
set dd=cd&rem
echo [%dd%]
- - - - - - - - - - - -
(no space infront of the "&")

and than this
- - - - - - - - - - - -
set dd=cd &rem
echo [%dd%]
- - - - - - - - - - - -
(one-or-more spaces infront of the "&")

the "[" and "]" are just visual delimitors and have no special meaning.

You might notice that the second example displays a space infront of the
"]", while the first one doesn't.

you will get the same results when you leave the "&rem" parts off

Regards,
Rudy Wieser

R.Wieser
2022-07-03 20:13:00 UTC
Permalink
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.
Post by Kenny McCormack
Post by Herbert Kleebauer
set dd=cd
doskey cd=cd $* ^&call title %^%dd^%%
Indeed it does! Kudos to you for figuring that out.
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
2022-07-03 21:19:07 UTC
Permalink
Post by R.Wieser
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.
Post by Kenny McCormack
Post by Herbert Kleebauer
set dd=cd
doskey cd=cd $* ^&call title %^%dd^%%
Indeed it does! Kudos to you for figuring that out.
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
Did you try it? Here it works.
Post by R.Wieser
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%%
Post by R.Wieser
Easy to fix, either use "^%%dd^%%" - or just "%%dd%%". ("^%dd^%" doesn't
work)
The fix is the bug!
Post by R.Wieser
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^%%
Post by R.Wieser
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"
Post by R.Wieser
Also, IFAIKS that "call" in there is not needed.
Without the call it wouldn't work.
Post by R.Wieser
(caveat: I did my work under XPsp3)
R.Wieser
2022-07-04 07:53:11 UTC
Permalink
Herbert,
Post by Herbert Kleebauer
Post by R.Wieser
I think that you have found out by now that that doesn't quite work. For
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.
Post by Herbert Kleebauer
Post by R.Wieser
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.
Post by Herbert Kleebauer
Post by R.Wieser
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
Yeah, you already said that. The problem is that you are not *explaining*,
nor do I see you give any test results.
Post by Herbert Kleebauer
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)
Post by Herbert Kleebauer
Post by R.Wieser
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.
Post by Herbert Kleebauer
Post by R.Wieser
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
2022-07-04 10:52:51 UTC
Permalink
Post by R.Wieser
Post by Herbert Kleebauer
Post by R.Wieser
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%%%%
Post by R.Wieser
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
2022-07-04 11:46:07 UTC
Permalink
Herbert,
Post by Herbert Kleebauer
It does work on the command line but not in a batch file. If you want
I know. I just didn't get it to work.
Post by Herbert Kleebauer
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. :-)
Post by Herbert Kleebauer
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. :-)
R.Wieser
2022-07-04 12:22:26 UTC
Permalink
Herbert,
Post by R.Wieser
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
R.Wieser
2022-07-04 13:43:05 UTC
Permalink
Herbert,
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
2022-07-04 13:48:56 UTC
Permalink
Post by R.Wieser
Herbert,
Got another one : no intermediate environment variable and, IMHO, even
set doskey cd=cd $* ^&call title %%c^^d%%
(from within a batchfile)
... I must have /way/ to much time on my hands.
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
2022-07-04 15:50:25 UTC
Permalink
Post by R.Wieser
Got another one : no intermediate environment variable and, IMHO, even
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
2022-07-04 18:01:43 UTC
Permalink
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
2022-07-05 07:37:29 UTC
Permalink
Herbert,
Post by R.Wieser
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
Kenny McCormack
2022-07-04 12:08:12 UTC
Permalink
Post by R.Wieser
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
2022-07-04 12:13:29 UTC
Permalink
Kenny,
Post by Kenny McCormack
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
Kenny McCormack
2022-07-04 13:40:47 UTC
Permalink
Post by R.Wieser
Kenny,
Post by Kenny McCormack
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.
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.
Zaidy036
2022-07-05 14:54:48 UTC
Permalink
Post by Dallas
In a cmd.exe shell session how do I set the window title to the current directory path?
Maybe this will help:
<https://serverfault.com/questions/255291/get-directory-containing-the-currently-executed-batch-script>
Loading...