Re: How to UPCASE string in bat files?
- From: "VanguardLH" <V@xxxxxxxxx>
- Date: Fri, 29 Feb 2008 16:48:32 -0600
"Pegasus (MVP)" <I.can@xxxxxxxxxx> wrote in message news:OXj2WvueIHA.5996@xxxxxxxxxxxxxxxxxxxxxxx
"VanguardLH" <V@xxxxxxxxx> wrote in message news:292dnVhkN-sXtVXanZ2dnUVZ_vumnZ2d@xxxxxxxxxxxxxx"ILiya" <iliya00@xxxxxxxxx> wrote in message news:eab%23cpqeIHA.4260@xxxxxxxxxxxxxxxxxxxxxxx
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%
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.
.
- Prev by Date: Re: Worst design fault in windows.
- Next by Date: Re: Blue Screen Event 1003 Category 102
- Previous by thread: Re: PC Boots up by itself
- Next by thread: Re: Blue Screen Event 1003 Category 102
- Index(es):
Relevant Pages
|