Windows cmd: echo without new line but with CR

前端 未结 3 1572
情歌与酒
情歌与酒 2021-01-03 10:53

I would like to write on the same line inside a loop in a windows batch file. For example:

setlocal EnableDelayedExpansion
set file_number=0
for %%f in (*) d         


        
3条回答
  •  生来不讨喜
    2021-01-03 11:16

    The above no longer works in Windows 7 and later. I found the reason is delayed expansion that should be set after ASCII_13 assignment, maybe someone smart could explain why exactly.

    Anyway, the code below works both on Windows 7 and Windows 10.

    @set licz=0
    @setlocal
    @for /f %%a in ('copy /Z "%~dpf0" nul') do @set "ASCII_13=%%a"
    @setlocal enabledelayedexpansion
    :loop
    @set /a licz=licz+1
    @set /p "=Waiting time: %licz% seconds!ASCII_13!"  NUL
    @GOTO loop
    

    If you do not like the cursor blinking at beginning of the line, transfer ASCII_13 to the beginning to execute CR before text. Needs to be preceeded by any ASCII character, though, to avoid getting stripped. And this will be visible as the last char on the line, so be wary here :)

    @set /p "=.!ASCII_13!Waiting time: %licz% seconds" 

提交回复
热议问题