@echo off
:: file: lsdX.bat
::
:: kinda like tree command, but only shows dirs to given depth
::
:: (blame: shardy@@differentchairs.com)
if %1.==. goto help
if not %3.==. goto help
setlocal
set dir=*
if not %2.==. set dir=%2
set dir=%dir:"=%
set lvl=%1
(set lvlindent=^ )
(set lvlbump= )
if not exist "%dir%" goto done
echo --------^< %dir% ^>-------
if %lvl% LEQ 0 goto done
for /d %%d in ("%dir%") do (
if not %%d=="%dir%" echo %%d
call :showdirs %lvl% %%d
)
:done
endlocal
goto :eof
:showdirs
setlocal
set lvl=%1
set /a lvl-=1
if %lvl% LEQ 0 goto :eof
set dir=%*
set dir=%dir:"=%
:: pushd "%2" -- but need account for any embedded spaces
for /f "tokens=1*" %%f in ("%dir%") do pushd %%g
for /f "tokens=*" %%a in ('dir /b *') do (
(set lvlindent=%lvlindent%%lvlbump%)
echo %lvlindent%%%a
call :showdirs %lvl% "%%a"
)
popd
endlocal
goto :eof
:help
echo.
echo usage: lsdX ^<x^> [^<dirname^>]
echo.
echo ^<x^> is maximum depth to show
echo.