For example %cd% returns the current path. How to make what %cd% returns be
all in the upper or in lower case?
Thanks
============
Unfortunately there are no batch commands to perform this
function. You would have to examine each letter in turn and
translate it to its upper-case equivalent. A better alternative
would be to use an embedded VB Script:
@echo off
Set case=U
Set String=%CD%
echo > c:\tempVBS.vbs Set objArgs = WScript.Arguments
echo >>c:\tempVBS.vbs if objArgs.count = 0 then wscript.quit
echo >>c:\tempVBS.vbs wscript.echo %case%Case(objArgs(0))
for /F "tokens=*" %%* in ('cscript //nologo c:\TempVBS.vbs "%String%"') do
echo %%*
del c:\TempVBS.vbs
Set "case" to "U" or "L", and "String" to whatever you want
to translate.
Don't know any way of doing this directly in batch, though there might be a
clever and devious way of achieving it, as there are with a great many batch
functions.
AutoIt can do these kinds of things much more easily, e.g:
For example %cd% returns the current path. How to make what %cd%
returns be all in the upper or in lower case?
Thanks
Use character substitution with the 'set' command. Run 'set /?' to
see the comments on how to do substitution. Write a subroutine (i.e.,
a section outside the flow of control using a :label) that you call to
do the translation.
@echo off
setlocal
....
echo Original value = %CD%
call UPPER "%CD%"
echo Uppercased value = %var%
....
goto EndBatch <-- (see NOTE)
....
:UPPER
set var=%~1
set %var:a=A%
set %var:b=B%
set %var:c=C%
(repeat for each character)
exit
....
:EndBatch
....
NOTE: Use 'goto :EOF' if you don't have any cleanup at the end of the
batch script (might not be needed if you use 'setlocal').
This is just off the top of my head. I haven't tested for
correctness. Just providing some hints.
For example %cd% returns the current path. How to make what %cd% returns
be all in the upper or in lower case?
Thanks
Use character substitution with the 'set' command. Run 'set /?' to see
the comments on how to do substitution. Write a subroutine (i.e., a
section outside the flow of control using a :label) that you call to do
the translation.
@echo off
setlocal
...
echo Original value = %CD%
call UPPER "%CD%"
echo Uppercased value = %var%
...
goto EndBatch <-- (see NOTE)
...
:UPPER
set var=%~1
set %var:a=A%
set %var:b=B%
set %var:c=C%
(repeat for each character)
exit
...
:EndBatch
...
NOTE: Use 'goto :EOF' if you don't have any cleanup at the end of the
batch script (might not be needed if you use 'setlocal').
This is just off the top of my head. I haven't tested for correctness.
Just providing some hints.
I think you omitted a colon when calling your subroutine, and
some variable names in the subroutine itself. This is probably
what you meant:
@echo on
echo Original value = %CD%
call :UPPER "%CD%"
echo Uppercased value = %var%
goto :eof
:UPPER
set var=%~1
set Var=%var:a=A%
set Var=%var:b=B%
set Var=%var:c=C%
I think you omitted a colon when calling your subroutine, and
some variable names in the subroutine itself. This is probably
what you meant:
@echo on
echo Original value = %CD%
call :UPPER "%CD%"
echo Uppercased value = %var%
goto :eof
:UPPER
set var=%~1
set Var=%var:a=A%
set Var=%var:b=B%
set Var=%var:c=C%
Yep. I didn't bother to waste the time to actually write a batch
script to go testing the hints that I provided. As I said, "This is
just off the top of my head." For the 'call' command, the colon is
needed with the label to differentiate that you are specifying a
filename in the 'call' command. As I mentioned with running 'set /?',
the OP should also run 'call /?' to get help on that command.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.