This converts to uppercase even though drive x: doesn't exist. Then you
just have to remove the colon.
for %%a in (x:) do echo %%~da
Oddly, this (with backslash) does nothing (it returns the value in the same
case in which it was given), whether or not the drive exists.
for %%a in (x:\) do echo %%~da
But this converts to uppercase if the name exists.
for %%a in (x:\name) do echo %%~da
Now how can you do it to lowercase?
--
Reply in group, but if emailing add one more
zero, and remove the last word.
Converting the case of a variable is covered in
http://www.netikka.net/tsneti/info/tscmd039.htm
Works both ways.
Also http://www.netikka.net/tsneti/info/tscmd.php#namedown
All the best, Timo
--
Prof. Timo Salmi, Vaasa, Finland
http://www.netikka.net/tsneti/homepage.php
What input and output such:
http://storage1.static.itmages.ru/i/11/0220/h_1298234783_a6b2a373c3.png
A little tickle:
set var_=%%%1%%
endlocal&set %1=%var_%&goto :eof
(and remove the SET var_=%var_:"=% )
will allow
CALL :toupper somevar
to change somevar's contents to upper-case
*scratches head* I Am very tired - this doesn't seem to work here.
@echo off
set a=abc
call :toupper a
echo %a%
call :toupper %a%
echo %a%
pause
goto :EOF
:toupper
set var_=%%%1%%
endlocal&set %1=%var_%&goto :eof
--
Regards,
Mic
@echo off
setlocal
set "var=qwerty"
for /f "tokens=2 delims=:" %%i in ('
2^>^&1 find /c /v "" "%var%"
') do echo %%i
More likely I'm being too vague. Also, that should have been "CALL set
var_=%%%1%%"
In the Book of Timo, Chapter 39, verse 1 we find:
@echo off & setlocal enableextensions
set myvar_=My Test String! וצה
echo %myvar_%
call :ToUpcase "%myvar_%" myvar_
echo %myvar_%
endlocal & goto :EOF
::
:: ======================
:ToUpcase
setlocal enableextensions
set var_=%1
set var_=%var_:a=A%
set var_=%var_:b=B%
[snip[*]]
set var_=%var_:z=Z%
set var_=%var_:"=%
endlocal & set %2=%var_%& goto :EOF
[*] : there are Scandinavian conversions after "z" that have been snipped
also
In the above, if you change
set var_=%1 TO call set var_=%%%1%%
endlocal & set %2=%var_%& goto :EOF TO endlocal&set %1=%var_%&goto :eof
and remove the SET var_=%var_:"=%
we get: (just the meat...)
:ToUpcase
setlocal enableextensions
set var_=%%%1%%
set var_=%var_:a=A%
set var_=%var_:b=B%
...
set var_=%var_:z=Z%
REM set var_=%var_:"=%
endlocal & set %1=%var_%& goto :EOF
and with a routine where executing
CALL :toupcase myvar_
should render myvar_ to upper-case
demo: (converting only A,B,Z for brevity...)
This solution developed using XP
It may work for NT4/2K
----- batch begins -------
[1]@echo off
[2]setlocal
[3]set var=AaBbZz%%abz%%+!zba!+(z,b,a)"baz"
[4]echo before=%var%=
[5]call :toup var
[6]echo after =%var%=
[7]goto :eof
[8]
[9]::
[10]:: convert %1 to upper-case (abbreviated)
[11]::
[12]:toup
[13]setlocal enableextensions
[14]call set var_=%%%1%%
[15]set var_=%var_:a=A%
[16]set var_=%var_:b=B%
[17]set var_=%var_:z=Z%
[18]endlocal&set %1=%var_%&goto :eof
------ batch ends --------
Lines start [number] - any lines not starting [number] have been wrapped and
should be rejoined. The [number] that starts the line should be removed
The label :eof is defined in NT+ to be end-of-file but MUST be expressed as
:eof
So - whereas Timo's routine uppercases a string to a variable, if the string
is already in a variable, this modified routine will convert it to
upper-case, which I find a little more convenient.
- It obviates the need to quote the subject string if separators are
required
- It does not strip-out quotes
In fact, warming to the theme
[19]:toup
[20]setlocal enableextensions
[21]call set var_=%%%1%%
[22]if not defined var_ goto todone
[23]set var_=%var_:a=A%
[24]set var_=%var_:b=B%
[25]set var_=%var_:z=Z%
[26]:todone
[27]endlocal&set %1=%var_%
[28]if not "%2"=="" shift&goto toup
[29]goto :eof
would allow
CALL :toup some series of variables
to upper-case the variables "some","series","of" and "variables"
I changed the delims to * and see this:
File not found - QWERTY
so perhaps there is a locality difference.
This works:
@echo off
setlocal
set "var=qwerty DE NoP"
for /f "tokens=4,*" %%i in ('
2^>^&1 find /c /v "" "%var%"
') do echo %%j
--
Regards,
Mic
Umm - doesn't work if the target string is an existing filename...or is an
afn that hits a target...
An easy fix. :)
@echo off
setlocal
set "var=qwerty DE NoP"
for /f "tokens=2 delims=>" %%i in ('
2^>^&1 find /c /v "" ">%var%"
') do echo %%i
--
Regards,
Mic
Closer - poison characters are ? and * (at least) - no case-conversion and
'"' affixed.
@echo off
setlocal
set "var=qwerty"
echo %var%
for /f %%i in ('echo "%var%".toupper^(^) ^| powershell -c -') do set
"var=%%i"
echo %var%
for /f %%i in ('echo "%var%".tolower^(^) ^| powershell -c -') do set
"var=%%i"
echo %var%