これを試してみてください - あまりにも特殊記号を処理できる必要があります(それはendsWithサブルーチンを使用しています):
@echo off
:::example calls of :endsWith subroutine
call :endsWith abcdefgh fgh
echo %errorlevel%
call :endsWith abcdefgh abc
echo %errorlevel%
exit /b 0
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:endsWith [%1 - string to be checked;%2 - string for checking ]
@echo off
rem :: sets errorlevel to 1 if %1 ends with %2 else sets errorlevel to 0
setlocal EnableDelayedExpansion
set "string=%~1"
set "checker=%~2"
set LF=^
rem ** Two empty lines are required
rem echo off
for %%L in ("!LF!") DO (
for /f "delims=" %%R in ("!checker!") do (
set "var=!string:%%~R=%%L#!"
)
)
for /f "delims=" %%P in (""!var!"") DO (
set "temp=%%~P"
)
if "%temp%" EQU "#" (
endlocal & exit /b 1
) else (
endlocal & exit /b 0
)
goto :eof
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
あなたはまた、(それが外部コマンドに依存しているとして、おそらく遅くなります)FINDSTR
を使用することができます。
echo abcdefgh| findstr /e "fgh" >nul 2>nul && (
echo ends with
)||(
echo does not ends with
)
'SET'コマンドのヘルプファイルに記載されているように、部分文字列を使用することができます。 「IF/I」= "=="%cho:〜-7% "echo match' – Squashman