I've excerpted a part of the batch file that I'm using. I was experimenting with making progress bars, instead of numerical counts output by timeout.
My question is, how can I dynamically modify the string in a loop, rather than having to retype every step of the string?
@echo off
setlocal enabledelayedexpansion
:: This is to set variables that represent backspace and carriage return.
:: I begin strings with these, instead of ending strings with only CR,
:: so that the cursor isn't flashing under the first character of the
:: progress bar. Beginning each string with a space, and ending each
:: with !CR! only is another possible workaround.
for /f %%a in ('copy /Z "%~dpf0" nul') do set "CR=%%a"
for /f %%a in ('"prompt $H&for %%b in (0) do rem"') do set "BS=%%a"
<nul set /p"= [ ]" & Timeout /t 1 >nul
<nul set /p"=!BS!!CR![■ ]" & Timeout /t 1 >nul
<nul set /p"=!BS!!CR![■■ ]" & Timeout /t 1 >nul
<nul set /p"=!BS!!CR![■■■ ]" & Timeout /t 1 >nul
<nul set /p"=!BS!!CR![■■■■ ]" & Timeout /t 1 >nul
<nul set /p"=!BS!!CR![■■■■■ ]" & Timeout /t 1 >nul
<nul set /p"=!BS!!CR![■■■■■■ ]" & Timeout /t 1 >nul
<nul set /p"=!BS!!CR![■■■■■■■ ]" & Timeout /t 1 >nul
<nul set /p"=!BS!!CR![■■■■■■■■ ]" & Timeout /t 1 >nul
<nul set /p"=!BS!!CR![■■■■■■■■■ ]" & Timeout /t 1 >nul
<nul set /p"=!BS!!CR![■■■■■■■■■■]" & Timeout /t 1 >nul
As you can see, I currently type eleven commands (well, copy/paste then modify each line) to create the progress of a progress bar.
I would prefer to have a loop that adjusts the width of the bar to the number of times it will loop, then replaces the leftmost space with a block each loop. It would let me re-use this for a wait of any length, or even to show the progress of batch processes that I don't want to flood the screen with, without needing extensive modifications each time.
Unfortunately, I'm not honestly very knowledgeable about batch; I know enough to hack things together with some Google-Fu, but my search terms are not giving me good results with this, and I am not sure that what I'm trying to do is feasible. Any help, even just a starting point, would be appreciated.