Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Use command-line reference in a script to convert an uppercase str

1 réponse
Avatar
Bruno
In a generic command script we want to use the %computername% environment
variable.
But the result is in upper case e.g. "HAW11" (even if the computer name is
"haw11").

The thrid part tool requires the name to be in lower case : haw11.

Is there anyway to convert the uppercase string to a lowercase string in a
command script.

Regards.


Bruno

1 réponse

Avatar
Gilles LAURENT
"Bruno" a écrit dans le message de
news:

[...]

| Is there anyway to convert the uppercase string to a lowercase string
| in a command script.

Below an example of script which include the conversion subroutine :

-- cut here : _toLower.cmd --

@echo off

call :_tolower %computername%
echo [%_toLower%]

call :_tolower CONVERT ME TO LOWERCASE
echo [%_toLower%]

goto :eof

rem converts a string to all lower case letters
rem on input the string to convert to lowercase
rem on output the environment variable %_toLower% contains
rem the converted string
:_toLower
echo>"%temp%%*"
for /f "tokens=*" %%i in ('dir/b/l "%temp%%*"') do set _toLower=%%i
del "%temp%%*"

-- cut here : toLower.cmd --

Hope this helps. Let us know.

--
Gilles LAURENT
Me contacter : http://cerbermail.com/?zoTY7ZkLcD