Pregunta

So I'm looking for a quick command to evaluate the length of environment variables on the windows command line.

Conceptually, something to the effect of:

echo %PATH%.length

Thanks!

¿Fue útil?

Solución

@echo off
setlocal enabledelayedexpansion
call :COUNT "%path%"
echo Your variable is %length% characters long
pause >nul

:COUNT
set temp=%1
set length=0
:loop
if defined temp (
    set temp=!temp:~1!
    set /a length+=1
    goto :loop
)

Usage: call :COUNT %yourvar% and the length will be stored in %length%.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top