在 Windows 的 CMD shell 中,tree 命令并不直接支持指定层数。
@echo off
setlocal
set "root=%~1"
set "maxdepth=%~2"
set "curdepth=0"
set "indent="
:loop
pushd "%root%"
for /d %%D in (*) do (
echo %indent%+-- %%D
if %curdepth% lss %maxdepth% (
set /a "curdepth+=1"
set "root=%%D"
set "indent=%indent% "
call :loop
set "indent=%indent:~,-4%"
set /a "curdepth-=1"
)
)
popd
exit /b
tree_depth.cmd C:\path\to\directory 2
标签:set,indent,%%,cmd,子目录,curdepth,层数
From: https://www.cnblogs.com/yhm138/p/17708017.html