JSI Tip 8025. How many levels have I Pushd into the stack?

Jerold Schulman

May 11, 2004

1 Min Read
ITPro Today logo in a gray background | ITPro Today

The Pushd command stores the name of the current directory for use by the Popd command, before changing the current directory to the specified directory.

I have scripted PushdLevel.bat to return the current number of levels you have pushed into the stack.

The syntax for using PushdLevel.bat is:

call pushdlevel level

Where level is a call directed numeric environment variable that will contain the Pushd level, from 0 (none) through N.

NOTE: See 'CMD does not support UNC paths as current directories'?

PushdLevel.bat contains:

@echo offIf {%1}=={} @echo Syntax PushdLevel Level&exit /b 1set /a %1=0if exist "%TEMP%%~n0.TMP" del /q "%TEMP%%~n0.TMP"pushd >"%TEMP%%~n0.TMP"for /f "Tokens=1 Delims=:" %%L in ('type "%TEMP%%~n0.TMP"^|findstr /v /n /c:"[$#$]"') do (     set /a %1=%%L)del /q "%TEMP%%~n0.TMP"exit /b 0



Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like