Determining PUSHD levels

  • Thread starter Thread starter David Trimboli
  • Start date Start date
D

David Trimboli

If you use PUSHD to change the current directory, and if command extensions
are enabled, the prompt code $+ will tell you how many levels have been
PUSHD onto the stack. Is there some way to determine this besides
displaying it in the prompt?

David
Stardate 4349.3
 
David said:
If you use PUSHD to change the current directory, and if command
extensions are enabled, the prompt code $+ will tell you how many
levels have been PUSHD onto the stack. Is there some way to
determine this besides displaying it in the prompt?

David
Stardate 4349.3

There may well be a simpler technique but the following will work,
simply copy and paste into a file named something.CMD -

[SCRIPT]
:: Sets the environment variable DEPTH to the number of
:: PUSHD directories on the stack
@echo off

pushd >%TEMP%\pushdDEPTH.TMP

for /f %%c in ('type %TEMP%\pushdDEPTH.TMP ^| find /c ^^
/v "NoTvErYlIkElYeVeNoNcE"') do (
set DEPTH=%%c
)

del %TEMP%\pushdDEPTH.TMP 2>nul
[/SCRIPT]

HTH

Dean
 
Dean said:
pushd >%TEMP%\pushdDEPTH.TMP

for /f %%c in ('type %TEMP%\pushdDEPTH.TMP ^| find /c ^^
/v "NoTvErYlIkElYeVeNoNcE"') do (
set DEPTH=%%c
)

Neat trick! Any idea why pushd accepts being redirected, but not piped?

I noticed that, for example,

pushd | find /c /v "NoTgOnNaFiNdThIs"

doesn't work. (Always returns 0.)
 
Jim said:
Neat trick! Any idea why pushd accepts being redirected, but not
piped?

I noticed that, for example,

pushd | find /c /v "NoTgOnNaFiNdThIs"

doesn't work. (Always returns 0.)

Badly written I'm guessing ... played with that for a few mins. and got
annoyed, I even tried splitting standard out and standard error but to
no avail ... thus the use of a TEMP file ... grrr!

Dean
 
Dean Wells said:
Badly written I'm guessing ... played with that for a few mins. and got
annoyed, I even tried splitting standard out and standard error but to
no avail ... thus the use of a TEMP file ... grrr!

Dean
There are some drawback's with the real (simultaneous) pipes used
with a secondary cmd. This secondary cmd has an empty pushd - stack and
so can't return the level of the primary.
 
Matthias said:
There are some drawback's with the real (simultaneous) pipes used
with a secondary cmd. This secondary cmd has an empty pushd - stack
and so can't return the level of the primary.

I find that unlikely as a possible cause since the pushd command is
running within the context of the command prompt that does possess a
pushd stack, only its output is piped.
 
Dean Wells said:
I find that unlikely as a possible cause since the pushd command is
running within the context of the command prompt that does possess a
pushd stack, only its output is piped.
Hmm, maybe there is another undetected reason. I examined this same
behaviour when using

set PushdCnt=0
for /F %%A in ('pushd') do set /A PushdCnt+=1

And here the reason seems to the secondary cmd involved.
My posting on this tonight got somehow lost.
 
Matthias said:
Hmm, maybe there is another undetected reason. I examined this same
behaviour when using

set PushdCnt=0
for /F %%A in ('pushd') do set /A PushdCnt+=1

And here the reason seems to the secondary cmd involved.
My posting on this tonight got somehow lost.

I've experienced similar behavior using a "for-in-do" ... most
irritating is its insistance on using the root of the drive when
executing the "in" component.
 
Matthias said:
Hmm, maybe there is another undetected reason. I examined this same
behaviour when using

set PushdCnt=0
for /F %%A in ('pushd') do set /A PushdCnt+=1

And here the reason seems to the secondary cmd involved.
My posting on this tonight got somehow lost.

Eye reellie hayte maykin spelin mystaiks ...
 
Matthias said:
Dean,
please help a foreigner with poor english - what are you refering to?

I misspelled "insistence" as "insistance" ... my English teacher would
be an unhappy man ... as would my Mum! :)
 
Dean Wells said:
I misspelled "insistence" as "insistance" ... my English teacher would
be an unhappy man ... as would my Mum! :)
I was just wondering, cause your posting is a follow up to mine and not
to your own - where I didn't notice the fault - no dictionary at hand :-)
 
Dean Wells said:
David said:
If you use PUSHD to change the current directory, and if command
extensions are enabled, the prompt code $+ will tell you how many
levels have been PUSHD onto the stack. Is there some way to
determine this besides displaying it in the prompt?

David
Stardate 4349.3

There may well be a simpler technique but the following will work,
simply copy and paste into a file named something.CMD -

[SCRIPT]
:: Sets the environment variable DEPTH to the number of
:: PUSHD directories on the stack
@echo off

pushd >%TEMP%\pushdDEPTH.TMP

for /f %%c in ('type %TEMP%\pushdDEPTH.TMP ^| find /c ^^
/v "NoTvErYlIkElYeVeNoNcE"') do (
set DEPTH=%%c
)

del %TEMP%\pushdDEPTH.TMP 2>nul
[/SCRIPT]


Ohhhhhh! PUSHD by itself lists the stack of directories. I didn't realize
that. How silly of me!

But your script is clever nonetheless, and I agree that it's strange that
PUSHD can accept redirection but not pipes. Thanks!

David
Stardate 4357.4
 
Back
Top