Advertisement
jcunews

CountDirNestingLevels.bat

May 24th, 2024 (edited)
558
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 1.01 KB | None | 0 0
  1. @echo off
  2. setlocal
  3. if "%~1" == "" (
  4.   echo In Explorer, drag a directory/folder onto this batch file.
  5.   pause
  6.   goto :eof
  7. )
  8. 2>nul pushd %1
  9. if errorlevel 1 (
  10.   echo Only a directory/folder can be dropped onto this batch file.
  11.   pause
  12.   goto :eof
  13. )
  14. if "%cd:~-1%" neq "\" (
  15.   set "curdir=%cd%\"
  16. ) else set "curdir=%cd%"
  17. set maxlevels=0
  18. set mldir=(n/a)
  19. set /p =Counting <nul
  20. for /r . /d %%D in (*) do call :process "%%D"
  21. echo.
  22. echo.
  23. echo Base directory:
  24. echo %cd%
  25. echo.
  26. echo Max. directory nesting levels relative to above base directory:
  27. echo %maxlevels%
  28. echo.
  29. echo First found directory with max. nesting levels:
  30. echo %mldir%
  31. echo.
  32. pause
  33. goto :eof
  34.  
  35. :process
  36. set /p =.<nul
  37. set "relpath=%~1"
  38. call set "relpath=%%relpath:%curdir%=%%"
  39. set "relpath=%relpath: =_%"
  40. set "relpath=%relpath:)=_%"
  41. set "relpath=%relpath:&=_%"
  42. set "relpath=%relpath:\= %"
  43. set numlevels=0
  44. for %%A in (%relpath%) do set /a numlevels+=1
  45. if %numlevels% gtr %maxlevels% (
  46.   set maxlevels=%numlevels%
  47.   set "mldir=%~1"
  48. )
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement