Question

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!

Était-ce utile?

La solution

@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%.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top