Sem entrar em detalhes, preciso de um arquivo em lote que extraia um conjunto de nomes de seções de um arquivo INI. Felizmente, todos os nomes de seção que eu quero começam com a mesma string, então é moleza, certo? O problema é que o nome da seção pode incluir "%20". Por exemplo, este arquivo INI:
[Testing\Test%20x]
A=aaa
B=bbb
Infelizmente, findstr substitui% 20 por 0. Aqui está o que eu criei para meu arquivo em lote:
@ECHO off
SETLOCAL
FOR /F "delims=" %%A IN ('findstr \[Testing* Test.ini') DO (CALL :DOIT %%A)
ENDLOCAL
GOTO :EXIT
:DOIT
SET First=%1
SET Second=%First:[=%
SET Third=%Second:]=%
SET Fourth=%Third:0=20%
SET Fifth=%Fourth:20=%%20%
ECHO %1 %First% %Second% %Third% %Fourth% %Fifth%
EXIT /B
:EXIT
O que produz a saída:
[Testing\Test0x] [Testing\Test0x] Testing\Test0x] Testing\Test0x Testing\Test20x Testing\Testx0
Escapar da porcentagem com uma barra invertida ou um cursor não funciona. Como posso colocar o sinal de porcentagem na string?