Advertisement
npocmaka

PushDCounter

May 4th, 2013
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. :pushd_counter
  2. rem -- counts the number of pushd calls
  3. rem -- by Vasil "npocmaka" Arnaudov
  4. @echo off
  5. set prompt_backup=%prompt%
  6. prompt $+
  7. ( echo on
  8.    for %%a in (1) do ( @rem
  9.    )
  10. )>%temp%\p.tmp
  11. @echo off
  12. prompt %prompt_backup%
  13. set "prompt_backup="
  14. for /f "usebackq tokens=1,2,3 delims=() " %%P in ("%temp%\p.tmp") do (
  15.     set pushes=%%P
  16.     goto :end_for
  17. )
  18. :end_for
  19. call :strlen0.3  pushes
  20. del %temp%\p.tmp /s /q >nul
  21. goto :eof
  22.  
  23. :strlen0.3  StrVar  [RtnVar]
  24.   setlocal EnableDelayedExpansion
  25.   set "s=#!%~1!"
  26.   set "len=0"
  27.   for %%A in (2187 729 243 81 27 9 3 1) do (
  28.     set /A mod=2*%%A
  29.     for %%Z in (!mod!) do (
  30.         if "!s:~%%Z,1!" neq "" (
  31.             set /a "len+=%%Z"
  32.             set "s=!s:~%%Z!"
  33.            
  34.         ) else (
  35.             if "!s:~%%A,1!" neq "" (
  36.                 set /a "len+=%%A"
  37.                 set "s=!s:~%%A!"
  38.             )
  39.         )
  40.     )
  41.   )
  42.   endlocal & if "%~2" neq "" (set %~2=%len%) else echo %len%
  43. exit /b
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement