Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
Docfxit
- Posts: 132
- Joined: 12 Nov 2015 12:42
#1
Post
by Docfxit » 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%
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
-
Batcher
- Posts: 74
- Joined: 16 Apr 2009 10:36
#2
Post
by Batcher » 22 Nov 2023 01:58
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
-
Batcher
- Posts: 74
- Joined: 16 Apr 2009 10:36
#3
Post
by Batcher » 22 Nov 2023 02:03
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
-
Docfxit
- Posts: 132
- Joined: 12 Nov 2015 12:42
#4
Post
by Docfxit » 22 Nov 2023 10:33
That's really great.
Thank you very much,
Happy Thanksgiving...
-
Squashman
- Expert
- Posts: 4486
- Joined: 23 Dec 2011 13:59
#5
Post
by Squashman » 22 Nov 2023 20:39
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