Convert char to lowercase in batch

£可爱£侵袭症+ 提交于 2019-12-23 01:37:26

问题


I am having trouble trying to convert a windows path into the cygwin-style linux like path. C:\path\to\file will be /cygdrive/c/path/to/file for instance. I have everything working except for converting the uppercase drive letter pulled out of the path to lowercase. The link everyone gives for these questions is:

http://www.robvanderwoude.com/battech_convertcase.php

and the for loop under "SET, Take Two" seemed the most appropriate. This is what I have so far:

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION

SET CWRSYNCHOME=%~dp0

echo the windows path is %CWRSYNCHOME%
for /f "tokens=1,2 delims=:" %%a in ("%CWRSYNCHOME%") do (
set "manip1=%%a"
set "manip2=%%b"
echo starts as /cygdrive/!manip1!!manip2:\=/!
FOR %%i IN ("A=a" "B=b" "C=c" "D=d" "E=e" "F=f" "G=g" "H=h" "I=i" "J=j" "K=k" "L=l" "M=m" "N=n" "O=o" "P=p" "Q=q" "R=r" "S=s" "T=t" "U=u" "V=v" "W=w" "X=x" "Y=y" "Z=z") DO SET "manip1=%manip1:!%%i!%"&echo doing: "manip1=%manip1:!%%i!%"&echo now its !manip1!
set "CYGLIKEHOME=/cygdrive/!manip1!!manip2:\=/!"
)
echo the converted path is %CYGLIKEHOME%
PAUSE
GOTO :EOF

The output I get is:

the windows path is E:\cwRsync_5.5.0_x86_Free\SANDBOX\
starts as /cygdrive/E/cwRsync_5.5.0_x86_Free/SANDBOX/
the converted path is /cygdrive/ "manip1="
now its  "manip1="
now its  "manip1="
now its  "manip1="
now its  "manip1="
now its  "manip1="
now its  "manip1="
now its  "manip1="
now its  "manip1="
now its  "manip1="
now its  "manip1="
now its  "manip1="
now its  "manip1="
now its  /cwRsync_5.5.0_x86_Free/SANDBOX/
Press any key to continue . . .

is there a better way to convert a single char to lowercase? If not, can you guys see what I'm doing incorrectly when setting CYGLIKEHOME?

Thank you


回答1:


!%%i! makes no sense at all.

%manip1:!%%i!% should be !manip1:%%~i!



来源:https://stackoverflow.com/questions/36776895/convert-char-to-lowercase-in-batch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!