How to escape reserved characters in Windows batch files

后端 未结 2 700
粉色の甜心
粉色の甜心 2020-12-21 21:01

I\'m trying to process a list of file names but don\'t know how to \"escape\" the command line to produce consistent output regardless of whether the name contains plain tex

2条回答
  •  孤城傲影
    2020-12-21 21:48

    I think this will work as well.

    @echo off
    
    set /a COUNT=0
    for /f "tokens=*" %%g in ('dir /b *.txt') do (
        set /a COUNT+=1
        set "file=%%g"
        call :LIST file COUNT
    )
    pause
    exit
    
    :LIST
    setlocal enabledelayedexpansion
    echo !%2! !%1!
    endlocal
    goto :EOF
    

    Output

    1 01 A Test.txt
    2 02 & Test.txt
    3 03 ! test.txt
    4 04 % test.txt
    Press any key to continue . . .
    

提交回复
热议问题