我在嘗試將Windows路徑轉換爲cygwin樣式的linux路徑時遇到了問題。例如,C:\ path \ to \ file將會是/ cygdrive/c/path/to/file。除了將從路徑中拉出的大寫驅動器號轉換爲小寫字母之外,我有所有工作。鏈接大家給出了這些問題是:將char轉換爲小寫批處理
http://www.robvanderwoude.com/battech_convertcase.php
和下環「SET,以兩個」似乎是最合適的。這是我到目前爲止有:
@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 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 . . .
是有更好的方法來轉換一個單一字符爲小寫?如果沒有,你們可以在設置CYGLIKEHOME時看到我做錯了嗎?
謝謝
爲什麼你不使用cygpath的轉換? – matzeri
[這裏有一些其他可能的想法](http://stackoverflow.com/a/34723215/1683264)。 – rojo