Page 1 of 1

Change to upper case and add a :

Posted: 22 Nov 2023 00:54
by Docfxit
I would like to make sure the input letter is upper case and I would like to add a :
the code below doesn't add the colin.

Code: Select all

setlocal EnableDelayedExpansion

set /p Drive=Please enter drive letter. Example C 
call :Uppercase Drive
set "colin = :"
set "Drive &= %colin%"
Echo %Drive%
pause
goto:eof

:Uppercase
set %~1=!%1:a=A!
set %~1=!%1:b=B!
set %~1=!%1:c=C!
set %~1=!%1:d=D!
set %~1=!%1:e=E!
set %~1=!%1:f=F!
set %~1=!%1:g=G!
set %~1=!%1:h=H!
set %~1=!%1:i=I!
set %~1=!%1:j=J!
set %~1=!%1:k=K!
set %~1=!%1:l=L!
set %~1=!%1:m=M!
set %~1=!%1:n=N!
set %~1=!%1:o=O!
set %~1=!%1:p=P!
set %~1=!%1:q=Q!
set %~1=!%1:r=R!
set %~1=!%1:s=S!
set %~1=!%1:t=T!
set %~1=!%1:u=U!
set %~1=!%1:v=V!
set %~1=!%1:w=W!
set %~1=!%1:x=X!
set %~1=!%1:y=Y!
set %~1=!%1:z=Z!
goto:eof

cmd /k

Re: Change to upper case and add a :

Posted: 22 Nov 2023 01:58
by Batcher
1.bat

Code: Select all

@echo off
setlocal EnableDelayedExpansion
set /p Drive=Please enter drive letter. Example C 
for %%j in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
    set "Drive=!Drive:%%j=%%j!"
)
set "colin=:"
set "Drive=%Drive%%colin%"
echo %Drive%
pause

Re: Change to upper case and add a :

Posted: 22 Nov 2023 02:03
by Batcher
2.bat

Code: Select all

@echo off
set /p Drive=Please enter drive letter. Example C 
for /f "delims=" %%i in ('powershell -c "'%Drive%'.ToUpper()"') do (
    set "Drive=%%i"
)
set "colin=:"
set "Drive=%Drive%%colin%"
echo %Drive%
pause

Re: Change to upper case and add a :

Posted: 22 Nov 2023 10:33
by Docfxit
That's really great.

Thank you very much,

Happy Thanksgiving...

Re: Change to upper case and add a :

Posted: 22 Nov 2023 20:39
by Squashman
Docfxit wrote:
22 Nov 2023 00:54
I would like to make sure the input letter is upper case and I would like to add a :
the code below doesn't add the colin.

Code: Select all

setlocal EnableDelayedExpansion

set /p Drive=Please enter drive letter. Example C 
call :Uppercase Drive
set "colin = :"
set "Drive &= %colin%"
Echo %Drive%


cmd /k
You cannot be that loose with syntax in batch files. You created two variable names that end in a space. So you would have to add the space when you expand the variable.

Code: Select all

C:\Users\Squashman>set "drive =C"

C:\Users\Squashman>echo %drive %
C
I warned you about this a few years ago in this thread