Windows Command Prompt print text file with delay - windows

I have no experience with command prompt whatsoever, but I'd like to make a batch script (for fun and learn) that would print a text file from a given location, line by line, with a 1 second delay.
I would also want it to be able to pause/unpause when I press a designated key (ex: space) and feed me an extra line (on top of those already programmed to run) when I press another key (ex: enter).
I know I can add a 1 second delay by pinging localhost ping -n 5 127.0.0.1 > nul
And I know I can see the content of a text file using more text.txt, but I don't know how to iterate through an entire text file until EOF is met and I don't know how to pause/resume and feed extra line.
Hope it doesn't sound stupid or out of scope in this context, but it's just something that interests me right know and I know a lot people here have the knowledge to do this.

1) If you have experience in programming, you will know using a for loop is the most common way to do things one by one, e.g. line by line.
2) You can simply use ping localhost -n 2 >nul for 1 second delay, the 2 in the ping is not indicating 2 seconds, but 1 second instead. (I have no idea about that, just get used to it)
3) You can't pause/unpause when cmd is pinging, I mean there's no way to force the program to pause/unpause because the delay process is executed in just a line of code! Or you can magically add some code into it like ping localhost -n 2 pause while(KeyDown(SPACE)) >nul (just kidding :) )
4) Extra lines? Hmm... Remember batch is not a powerful language so... Yeah
Here is a simple code to print text line by line each second in a .txt file
for /f %%a in (your_text.txt) do (
echo %%a
ping localhost -n 2 >nul
)

You could do it synchronously with choice /t 1 (for a 1-second timeout) and some key other than Spacebar. Perhaps P for Pause?
#echo off
setlocal
set "textfile=notes.txt"
echo Hit P to pause / resume, Q to quit.
echo;
for /f "tokens=1* delims=:" %%I in ('findstr /n "^" "%textfile%"') do (
echo(%%J
choice /t 1 /c €pq /d € >NUL
if errorlevel 3 exit /b 0
if errorlevel 2 (
pause >NUL
ping -n 1 -w 750 169.254.1.1 >NUL
)
)
exit /b 0
Unfortunately, choice only allows a-z, A-Z, 0-9, and extended characters 128-254. There's no way to make it listen for Enter or Space. And choice is the only Windows command of which I'm aware that'll accept a single keypress and do something meaningful based on which key was pressed.
I think you'll have to use some sort of compiled language (or possibly PowerShell with a .NET class?) to listen for keypress events on the console. You could probably do it in JavaScript, but you'd have to display your output in a web browser or HTA window.

A "scrolling editor"? It is a crazy idea, isn't it? I LIKE IT! ;-) I adopted your project and add some points...
#echo off
rem ScrollEditor.bat: "dynamic" very simple line editor
rem Antonio Perez Ayala aka Aacini
if "%~1" neq "" if "%~1" neq "/?" goto begin
echo ScrollEditor.bat filename.ext
echo/
echo File lines will be continually scrolling, one per second.
echo/
echo You may pause the scroll via P key. In the "paused" state, the last displayed
echo line is named "current line", and the following commands are active:
echo/
echo #L Return/advance the listing to line #; continue the scroll from there.
echo [#]D Delete [from previous line # up to] current line.
echo I Insert lines after current line; end insert with *two* empty lines.
echo P End "paused" state; continue the scroll from current line on.
echo E End edit and save file, keep original file with .bak extension.
echo Q Quit edit, not save file.
goto :EOF
:begin
if not exist %1 echo File not found & goto :EOF
rem Load file lines into "line" array
set /P "=Loading file... " < NUL
setlocal DisableDelayedExpansion
for /F "tokens=1* delims=:" %%a in ('findstr /N "^" %1') do (
set "line[%%a]=%%b"
set "lastLine=%%a"
)
echo last line: %lastLine%
echo To pause scrolling, press: P
echo/
setlocal EnableDelayedExpansion
set "validCommands=LDIPEQ"
set currentLine=1
:command-P End "paused" state
:ScrollLine
if %currentLine% gtr %lastLine% (
set "currentLine=%lastLine%"
echo EOF
goto GetCommand
)
set "num= %currentLine%"
echo %num:~-4%: !line[%currentLine%]!
set /A currentLine+=1
choice /C PC /N /T 1 /D C >NUL
if errorlevel 2 goto ScrollLine
rem Enter paused state
set /A currentLine-=1
:GetCommand
echo/
set /P "command=Command [#L,#D,I,P,E,Q]? "
set "letter=%command:~-1%"
if "!validCommands:%letter%=!" equ "%validCommands%" goto GetCommand
goto command-%letter%
:command-L Go to line #; continue scrolling
set "currentLine=%command:~0,-1%"
goto ScrollLine
:command-D Delete from line # to current line
set "prevLine=%command:~0,-1%"
if not defined prevLine set "prevLine=%currentLine%"
rem Move lines after last deleted one into deleted lines
set /A currentLine+=1, newCurrent=prevLine-1, lines=currentLine-prevLine
for /L %%j in (%currentLine%,1,%lastLine%) do (
set "line[!prevLine!]=!line[%%j]!"
set /A prevLine+=1
)
set /A currentLine=newCurrent, lastLine=prevLine-1
if %currentLine% equ 0 set "currentLine=1"
echo %lines% line(s) deleted (current=%currentLine%, last=%lastLine%)
goto GetCommand
:command-I Insert lines after current one
echo End insert with *two* empty lines
echo/
rem Read new lines into "ins" array
set "newLine=%currentLine%"
:insertLine
set "line="
set /A newLine+=1
set "num= %newLine%"
set /P "line=+%num:~-3%: "
set "ins[%newLine%]=!line!"
rem The most complex part: end in two empty lines...
if not defined line (
set /A newLine+=1
set "num= !newLine!"
set /P "line=+!num:~-3!: "
if defined line (
set "ins[!newLine!]=!line!"
) else (
set /A newLine-=2
)
)
if defined line goto insertLine
rem Move old lines to new place to make room for new lines
set /A lines=newLine-currentLine, currentLine+=1, newLast=lastLine+lines
for /L %%j in (%lastLine%,-1,%currentLine%) do (
set "line[!newLast!]=!line[%%j]!"
set /A newLast-=1
)
rem Insert new lines in old place
for /L %%j in (%currentLine%,1,%newLine%) do set "line[%%j]=!ins[%%j]!"
set /A lastLine+=lines, currentLine=newLine
echo %lines% line(s) inserted (current=%currentLine%, last=%lastLine%)
goto GetCommand
:command-E End edit, save file
echo Saving file...
move /Y %1 "%~N1.bak"
(for /L %%i in (1,1,%lastLine%) do echo(!line[%%i]!) > %1
:command-Q Quit edit
echo End edit
This program have multiple problems: don't check for valid input in commands, may have problems with special Batch characters and if the first character of a line is a colon, eliminate it. However, it is a good starting point for this project!
Perhaps you may be interested in this similar project.

Related

How to make batch read certain parts of text and convert it into a variable

so I'm just wondering if it's possible to to make a batch file read a line of text but split every letter up into it's own variable, ex:
#echo off
:start
set /p text=input:
set out=
set out2=
set /p text=input:
:loop
set out=%out% %text:~0,1%
set out2=%out2:~1% %text:~1%
set text=%text:~1%
if defined text goto loop
echo %out% -%out2%
pause
goto start
What I've written here doesn't work (I was just fiddling around trying to find the answer)
But what I was trying to do was to make "out" and "out2" into 2 separate values. Where "out" would be the first letter typed, and "out2" would be the second letter and so on. (planning to have about 16 out's that can read the first 16 letters of whatever the user inputs and make it into separate varibles)
ex: typing "ab" in the same line would result in "out" being "a" and "out2" being b
Another thing I couldn't figure out either was how to stop "out" from reading everything after the first letter. If anyone could help me with this issue, please explain what you've done to fix it. Thanks in advance
Here is a little trick you can use with CMD.exe and the /U option. The FOR /F command is necessary to capture the output to assign to a variable. I then build a pseudo array with the cnt variable. The SET out command is just used to display all the variables in the pseudo array.
#echo off
setlocal
SET /P "text=INPUT:"
set "cnt=0"
for /F "delims=" %%G IN ('cmd /u /c "echo %text%"^|find /V ""') do (
set /A cnt+=1
CALL SET "out%%cnt%%=%%G"
)
FOR /L %%G IN (1,1,%cnt%) DO CALL echo %%out%%G%%
endlocal
pause
And here is just a quick run of the code.
C:\Users\Squashman\Desktop>so.bat
INPUT:foobar
out1=f
out2=o
out3=o
out4=b
out5=a
out6=r
Press any key to continue . . .
Here is the answer you provided but I fixed your logic errors.
#echo off
setlocal ENABLEDELAYEDEXPANSION
title Test
color a
mode 150
:start
cls
echo test
echo.
set /p text=Input:
set "texttmp=%text%"
set cnt=0
:Reader1
set /a cnt+=1
echo Val-%cnt% = !texttmp:~0,1!
set c[%cnt%]=!texttmp:~0,1!
set "texttmp=%texttmp:~1%"
if "%texttmp%" NEQ "" goto Reader1
I found an easy solution which is way easier to understand (for me at least)
#echo off
setlocal ENABLEDELAYEDEXPANSION
title Test
color a
mode 150
:start
cls
echo test
echo.
set /p text=Input:
set pos=1
:Reader1
echo Val-%pos% = !text:~%pos%,1!
set c[%pos%]=!text:~%pos%,1!
set /a pos=%pos%+1
if "!text:~%pos%,1!" NEQ "" goto Reader1
pause

make change on line and character x of txt file with cmd ( script)

As I am not an expert in script command and I am getting stuck on this script, I am asking the community for some help.
As for my problem I tried the following (see code below ) in order to change a character in a textfile on a specific location. By using For /F I was hoping to readout the entire file to a backup copy, and just change the wanted location to the new value by using an IF. However I noticed that when I put the token parameter to tokens=6 it wouldn't copy the entire file to the new location. so I changed this to tokens=*. However with this the entire row on the 74th line is changed. :s and with this I also found out that ENTERS and specific characters as "!" are not copied to the backup file.
Now i was hoping that you could help me change this character on location line 74 , token 6 without further resulting in any change of the specific text file.
thanks for any advise.
#echo off
CLS
setlocal enabledelayedexpansion
set ORIGINALFILE=test.file.txt
set MODIFIEDFILE=temp1.txt
set MODIFIEDFILE2=temp_backup.txt
set SEARCHVALUE=0
set REPLACEVALUE=1
set OUTPUTLINE=
set linenumber=0
::for demo purpose make cop of original file as original will be overwritten
copy %ORIGINALFILE% %MODIFIEDFILE2%
del temp1.txt
echo "all set"
timeout /t 2 /nobreak >nul
::everything is set now change the 6th item on the line 74 to a "1"
FOR /f "tokens=* delims=," %%G in ('"type %ORIGINALFILE%"') do (
set /a linenumber=!linenumber!+1
SET string=%%G
if !linenumber! EQU 61 (
SET modified=!string:%SEARCHVALUE%=%REPLACEVALUE%!
echo !linenumber!
) else (
echo !linenumber!
SET modified=!string!
)
echo !modified! >> %MODIFIEDFILE%
)
#ECHO OFF
SETLOCAL
set ORIGINALFILE=q34614930.txt
set MODIFIEDFILE=u:\temp1.txt
set MODIFIEDFILE2=u:\temp_backup.txt
set SEARCHVALUE=0
set REPLACEVALUE=1
::for demo purpose make cop of original file as original will be overwritten
copy %ORIGINALFILE% %MODIFIEDFILE2% >NUL 2>nul
REM echo "all set"
REM timeout /t 2 /nobreak >nul
::everything is set now change the 6th item on the line 5 to a "1"
(
FOR /f "tokens=1*delims=:" %%a in ('findstr /n /r ".*" "%ORIGINALFILE%"') do (
IF "%%a"=="5" (
FOR /f "tokens=1-6*delims=," %%A IN ("%%b") DO echo(%%A,%%B,%%C,%%D,%%E,%replacevalue%,%%G
) ELSE ECHO(%%b
)
)>"%MODIFIEDFILE%"
GOTO :EOF
I used a file named q34614930.txt containing some test data for my testing. I also changed the filenames to suit mys system.
In the absence of representative data, I use the following and replaced column 6 in line 5.
line 1,col2,col3,col4,col5,col6,col7,col8
line 2,col2,col3,col4,col5,col6,col7,col8
line 4,col2,col3,col4,col5,col6,col7,col8
line 5,col2,col3,col4,col5,col6,col7,col8
line 6,col2,col3,col4,col5,col6,col7,col8
Result
line 1,col2,col3,col4,col5,col6,col7,col8
line 2,col2,col3,col4,col5,col6,col7,col8
line 4,col2,col3,col4,col5,col6,col7,col8
line 5,col2,col3,col4,col5,1,col7,col8
line 6,col2,col3,col4,col5,col6,col7,col8
Without representative data, we're guessing.

Implementing timed input in batch file. (countdown to a minute)

I am using windows 8 to write a batch file and I got stuck in implementing the timer in batch file. I want to ask input from the user and give them one minute to type their input. Once the time hit a minute then display message like 'the time is over'. So, the time will start from 1 second and ends at 60 seconds OR start from 60 seconds and going down to 0 second. Either works just fine.
Additionally, I want timer to be displayed somewhere on screen so that they can see the countdown. Also, while the timer is running I want the user to be able to type a word and hit enter. This program will not make user wait, but it will wait until the time is over OR as soon as the user enter a word (whichever comes first). After they enter a valid word then I want to store that word in certain variable and do something like (goto VALIDWORD OR echo That is a valid word!)
I don't know if this is possible in batch file and there are more advanced language to use, but I want to complete this program using batch scripting. Thank you.
Following is my concept:
#echo off
:Start
color EC
set /a time =60
:loop
cls
if %time% EQU 0 goto Timesup
if %time% LEQ 60 goto CONTINUE
:CONTINUE
ping localhost -n 2 >nul
set /a time-=1
set /p cho= Enter your word:
echo Remaing Time: %time%
goto loop
:Timesup
echo The time is over!
exit
Any ideas or support would be appreciated. Again Thanks!
Batch files are not designed for tasks like this one, but it is possible to perform certain advanced managements although in a limited manner. The subroutine below use choice command to get input keys, so it does not allow to end the input with Enter key nor to delete characters with BackSpace; it use 0 and 1 keys for such tasks.
#echo off
setlocal
call :ReadTimedInput 60 word=
echo Word read: "%word%"
goto :EOF
:ReadTimedInput seconds result=
setlocal EnableDelayedExpansion
set /A seconds=100+%1
set "letters=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
for /F %%a in ('copy /Z "%~F0" NUL') do set "CR=%%a"
for /F %%a in ('echo prompt $H ^| cmd') do set "BS=%%a"
echo Enter a word; press 0 to End, press 1 to Clear
:clear
set /P "=X!CR! !CR!" < NUL
set "result="
:loop
set /P "=X!BS! !CR!%seconds:~-2%: %result%" < NUL
choice /C ¡10%letters% /N /CS /T 1 /D ¡ > NUL
if %errorlevel% equ 1 goto tick
if %errorlevel% equ 2 goto clear
if %errorlevel% equ 3 echo/& goto endInput
set /A char=%errorlevel%-4
set "result=%result%!letters:~%char%,1!"
:tick
set /A seconds-=1
if %seconds% gtr 100 goto loop
echo !CR!00
set "result=Time out"
:endInput
endlocal & set "%2=%result%"
exit /B

Batch File: List Directory & File names to individual variables and display as selection menu

I use RDP on many different windows machines, and sometimes have to RDP into one, then rdp from there onto another.
I'd like to know if it is possible to create a Batch File that can read the Names of all Directories within a set path, then display them as numbered variables like a menu.
After i input my selection, it would do the same for all .rdp files in the selected directory.
Below is an example of how i could manually hardcode it for each file...but I need something that will adapt to dropping an new rdp file into a directory rather than having to manually add it each time inside the batch file, as the number of sites/pcs and names can change regularly.
:site
ECHO Location List
ECHO.
ECHO 1 NSW
ECHO 2 QLD
ECHO.
SET /p site=Enter Selection:
IF "%site%"=="1" GOTO NSW
IF "%site%"=="2" GOTO QLD
:NSW
SET dirname=C:\Machine\NSW\
ECHO Machine List
ECHO.
ECHO 1 Client01.rdp
ECHO 2 Server01.rdp
ECHO 3 Server02.rdp
ECHO.
SET /p machine0=Enter Selection:
IF "%machine0%"=="1" SET machine1=%dirname%Client01.rdp
IF "%machine0%"=="2" SET machine1=%dirname%Server01.rdp
IF "%machine0%"=="3" SET machine1=%dirname%Server02.rdp
GOTO connection
:connection
mstsc %machine1% /console
I've found several questions similar to this (such as here and here) but they all seem to be about just displaying a list and not getting them into a menu like option, also i still do not fully understand how the FOR command works.
Example of the directory structure.
C:\Batchfile.bat
C:\Machines\NSW\Client01.rdp
C:\Machines\NSW\Server01.rdp
C:\Machines\NSW\Server02.rdp
C:\Machines\QLD\Client01.rdp
C:\Machines\QLD\Client02.rdp
C:\Machines\QLD\Server01.rdp
The base directory would be set to C:\Machines then batch would store each sub-directory name to a numbered variable and echo them to the screen and prompt for selection.
Location List
1 NSW
2 QLD
Enter Selection:_
If user input 1 then then it would store each .RDP filename inside the QLD sub-directory to a numbered variable and echo them to the screen and prompt for selection.
Machine List for NSW
1 Client01.rdp
2 Server01.rdp
3 Server02.rdp
Enter Selection:_
After the user makes a selection at this point i would like to use the selected .rdp file with the mstsc command to launch an rdp session to the selected computer then loop back the beginning to allow to open a second connection at the same time.
I'd appreciate any help you could give.
#ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
FOR /f "delims==" %%i IN ('SET s_ 2^>nul') DO SET "%%i="
SET "sourcedir=c:\sourcedir"
FOR /f "delims=" %%a IN ('dir/s/b/a-d "%sourcedir%\*.rdp"') DO (
SET s_=%%~dpa
FOR /f %%b IN ("!s_:~0,-1!") DO SET s_#%%~nb=Y&SET s_#%%~nb_%%~na=Y
)
CALL :showmenu "Location List" #
IF /i "%s_%"=="q" GOTO :EOF
SET s_site=%s_%
CALL :showmenu "Machine List for %s_site%" # %s_site%
IF /i "%s_%"=="q" GOTO :EOF
SET s_machine=%s_%
ECHO(==============
ECHO site=%s_site% machine=%s_machine%
GOTO :EOF
:showmenu
SET s_items=1
CLS
ECHO(%~1
ECHO(
FOR /f "tokens=2,3delims=_%2=" %%i IN ('set s_%2') DO (
IF "%3"=="" (
CALL :showline %%i
) ELSE (
IF "%3"=="%%i" CALL :showline %%j
)
)
ECHO(
SET "s_="
SET /p "s_=Enter Selection : "
IF NOT DEFINED s_ SET s_=Q
IF /i "%s_%"=="q" GOTO :EOF
IF DEFINED s_%s_% CALL SET s_=%%s_%s_%%%&GOTO :EOF
GOTO showmenu
:showline
SET "s_= %s_items%. "
ECHO %s_:~-4%%1
SET s_%s_items%=%1
SET /a s_items+=1
SET "s_%s_items%="
GOTO :eof
This way is self-adjusting. Unfortunately it also uses a few hieroglyphics...
The first step is to ensure that all variables with names starting s_ are removed from the environment. There's no special significance to s_ - it's just what I chose. The output of set s_ will be of the form s_whatever=something if an s_... variable exists. If none exist, the 2>nul suppresses the error message, but the > needs to be escaped by a caret (^) to tell cmd that the redirection is part of the command to be executed, not the for command. If s_whatever=something then the for /f will parse that line using = as a delimiter, hence assigning s_whatever to the nominated metavariable, %%i.
The next step is to find all of the .RDP filenames starting at the source directory. dir /s/b/a-d produces bare lines (no headers or footers) of the full filenames, suppressing any directorynames that happen to match the specified mask.
The entire filename is assigned to %%a because delims="" that is, there are no delimiters. S_ is used as a general-purpose variable and is assigned the drive and path parts of the filename in %%a. The last character of s_ is then removed (it will be a \) and the for /f %%b interprets the resultant string as though it was a filename. The variables s_#site and s_#site_machine are then set (to Y, but they could have been set to anything)
Note the use of !s_:~0,-1! which specifies to take character 0..last-1 of the run-time value of s_ - the ! specifies run-time value when SETLOCAL ENABLEDELAYEDEXPANSION is active.
The remainder of the main routine simply calls SHOWMENU twice with various parameters and assigns the value returned in s_ to the appropriate variable.
SHOWMENU sets the number of items (s_items) to 1 more than the count of items available, clears the screen and shows the menu title from the first subroutine parameter (%1) - but with the quotes suppressed (%~1) - which allows the parameter to contain spaces.
The following FOR/F tokenises the SET list for s_# (the SITE names) or s_# (the SITE+MACHINE names). Using delimiters of _ and = as well as the # or # means that for a line like s_#NSW=Y will assign NSW to %%i and a line like s_#NSW_Server01=Y assigns NSW to %%i and Server01 to %%j
The appropriate part is selected and passed to the SHOWLINE routine.
s_ is then used for user input. Forcing it to be cleared means that if the user presses just ENTER then it will remain unset - otherwise it would retain its original value.
I've arbitrarily assigned an input of Q to quit, and if there is no user input, then that quits, too. Otherwise, if the variable s_choicemade is set, then s_ is set to that value and reaching EOF returns from the subroutine. If an invalid choice is made, then s_invalidchoice will NOT be set, so the menu is re-displayed.
The SHOWLINE procedure sets s_ to spacethelinenumber.space and then the paraeeter is displayed (%1) preceded by the last 4 characters of that string. This means that if the item number exceeds 9 then the leading space wil be lopped off and the dots will be aligned. The item number is then incremented ready for the next choice.
Here is one way:
#echo off
setlocal enabledelayedexpansion
:Start
ECHO Location List
ECHO.
ECHO NSW
ECHO QLD
ECHO.
SET /p site=Enter Selection:
for /f %%a in ('dir /b/s "c:\Temp\%site%\*.rdp"') do (
set /a i+=1
echo !i! - %%~nxa
set mach[!i!]=%%~nxa
)
set /p m0=Enter Selection:
echo mstsc !mach[%m0%]! /console
set /p sel=Would you like to launch another [y/n]?
if /i "%sel%" EQU "y" Goto :start
Or
#echo off
setlocal enabledelayedexpansion
:Start
ECHO Location List
ECHO.
ECHO 1 - NSW
ECHO 2 - QLD
ECHO.
SET /p site=Enter Selection:
set i=0 & set a=0
set site[1]=NSW
set site[2]=QLD
for /f %%a in ('dir /b/s "c:\Temp\!site[%site%]!\*.rdp"') do (
set /a i+=1
echo !i! - %%~nxa
set mach[!i!]=%%~nxa
)
set /p m0=Enter Selection:
echo mstsc !mach[%m0%]! /console
set /p sel=Would you like to launch another [y/n]?
if /i "%sel%" EQU "y" Goto :start
Also, this is assuming all of your servers are 2003. Starting with 2008, I believe /console has been deprecated in lieu of /admin. If that's the case, it's easy enough to add a little more logic depending on which version of Server you're connecting to.

Is it possible to edit a line already outputted in Windows batch?

So, I am currently making a "loading screen", and to possibly save some space in my coding, I want to know if you could edit a line already outputted. I would have maybe a bracket [] as one stage of loading, so would it be possible to put one bracket, then wait and see if user presses C (for continue) for 1-2 seconds, and if not go to the next stage ([][])? I currently have a script where [] is set as load and for every stage, I do CLS and then echo %LOAD%[].
In addition, what if I just want to do a status update on a line, such as:
Checking status...
Loading server...
and then
Checking status... OK
Loading server... done
Bonus points if you can find me a character like █ that is compatible with Batch.
You can ommit the CLS and recreating the full screen with the help of set /p, as set /p doesn't output a newline, you can append text.
Normally set /p is for assigning text to a variable inputted by a user, but if you use redirection from NUL it simply outputs text.
#echo off
for /L %%n in (1 1 5 ) do (
<nul set /p ".=[]"
ping -n 2 localhost > nul
)
echo(
echo The end
The status update you asked for, can be handled the same way, as it only appends something to the line.
If you want to change parts of the line or the complete line, you need to move the cursor back or to the beginning of the line.
Both can be done with the backspace character or the carriage return character.
This is a sample which counts on a fixed screen location
setlocal EnableDelayedExpansion
for /f %%a in ('copy /Z "%~dpf0" nul') do set "CR=%%a"
for /L %%n in (1 1 1000) do (
<nul set /p ".=%%n!CR!"
)
Creating a blockchar like █ can be done with
setlocal EnableDelayedExpansion
for /F "usebackq tokens=1" %%c in (
`forfiles /p "%~dp0." /m "%~nx0" /c "cmd /c echo 0xde"`) do (
set BlockChar=%%c
)
echo %BlockChar%
Thanks to dbenham Generate nearly any character, including TAB, from batch

Resources