Jump to content

How to UPCASE string in bat files?


Recommended Posts

Posted

For example %cd% returns the current path. How to make what %cd% returns be all in the upper or in lower case?

Thanks

  • Replies 5
  • Created
  • Last Reply

Popular Days

Guest Pegasus \(MVP\)
Posted

Re: How to UPCASE string in bat files?

 

 

"ILiya" <iliya00@yandex.ru> wrote in message

news:eab%23cpqeIHA.4260@TK2MSFTNGP05.phx.gbl...

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.

Guest Anteaus
Posted

RE: How to UPCASE string in bat files?

 

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:

 

$cd = StringUpper(@WorkingDir)

msgbox(0,"Working Dir",$cd)

 

... and a whole lot more, even up to full GUI applets.

http://www.autoitscript.com

 

Another issue I notice with %cd% is that it may in some cases return the

'8.3' name, which is possibly not what you want.

 

"ILiya" wrote:

> For example %cd% returns the current path. How to make what %cd% returns be all in the upper or in lower case?

> Thanks

>

Guest VanguardLH
Posted

Re: How to UPCASE string in bat files?

 

"ILiya" <iliya00@yandex.ru> wrote in message

news:eab%23cpqeIHA.4260@TK2MSFTNGP05.phx.gbl...

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.

Guest Pegasus \(MVP\)
Posted

Re: How to UPCASE string in bat files?

 

 

"VanguardLH" <V@nguard.LH> wrote in message

news:292dnVhkN-sXtVXanZ2dnUVZ_vumnZ2d@comcast.com...

> "ILiya" <iliya00@yandex.ru> wrote in message

> news:eab%23cpqeIHA.4260@TK2MSFTNGP05.phx.gbl...

> 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%

Guest VanguardLH
Posted

Re: How to UPCASE string in bat files?

 

"Pegasus (MVP)" <I.can@fly.com.oz> wrote in message

news:OXj2WvueIHA.5996@TK2MSFTNGP04.phx.gbl...

>

> "VanguardLH" <V@nguard.LH> wrote in message

> news:292dnVhkN-sXtVXanZ2dnUVZ_vumnZ2d@comcast.com...

>> "ILiya" <iliya00@yandex.ru> wrote in message

>> news:eab%23cpqeIHA.4260@TK2MSFTNGP05.phx.gbl...

>> 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.


×
×
  • Create New...