如果路径中不含 & 这个符号的话,就会很好处理,但是,如果含有它的话,则会比较困难。以下演示代码借用了我头两天发的一段代码(点
这里 查看),能兼容路径中含有的、除了百分号之外的其他特殊符号:
@echo off
for /f "delims=" %%i in (list.txt) do call :pickup "%%i"
pause
goto :eof
:pickup
set "route=%~1"
call :antitone "%route%"
call :intercept "%str%"
call :antitone "%route%"
echo "%str%"
goto :eof
:antitone
set str=
set "var=%~1"
:loop1
if not "%var:~0,1%"=="" set "str=%str%%var:~-1%"
set "var=%var:~0,-1%"
if not "%var%"=="" goto loop1
goto :eof
:intercept
for /f "tokens=1*" %%i in (%1) do set "route=%%j"
goto :eof
If the path does not contain the & symbol, it will be very easy to handle. However, if it contains it, it will be more difficult. The following demonstration code borrows from a section of code I posted the other day (click
here to view), which can be compatible with other special symbols in the path except the percent sign:
@echo off
for /f "delims=" %%i in (list.txt) do call :pickup "%%i"
pause
goto :eof
:pickup
set "route=%~1"
call :antitone "%route%"
call :intercept "%str%"
call :antitone "%route%"
echo "%str%"
goto :eof
:antitone
set str=
set "var=%~1"
:loop1
if not "%var:~0,1%"=="" set "str=%str%%var:~-1%"
set "var=%var:~0,-1%"
if not "%var%"=="" goto loop1
goto :eof
:intercept
for /f "tokens=1*" %%i in (%1) do set "route=%%j"
goto :eof