- @echo off & setlocal
- set /p FilePath=文件路径(默认%ComSpec%):
- if %FilePath%|==| set FilePath=%ComSpec%
- set FilePath="%FilePath:"=%"
- for %%a in (%FilePath%) do call :GetChrCount "%%~dpa" "\"
- echo 目录层数:%errorlevel%
- pause
- goto :eof
-
- :GetChrCount
- set s=%~1
- set c=%~2
- :while
- call set o=%%s:~%i%,1%%
- if "%o%"=="" exit /b %n%
- if "%o%"=="%c%" set /a n+=1
- set /a i+=1
- goto while
复制代码
|