After some tests I discovered that after SET /P command reach its maximum size and return the characters read, it does NOT move the file pointer of the input file; this mean that the next SET /P command over the same file (redirected to a code block) continue reading the following characters. This point made possible to read the contents of a text file in blocks of 1 KB size and accumulate and process they in any way as long as the result fits in a variable, that is, be not longer than 8 KB.
Code: Select all
rem Read the next block of characters
set /A nextBlock+=1
(for /L %%i in (1,1,%nextBlock%) do (
set /P "block="
)) < input.txt
if not defined block goto endFile
rem Append next block to last part of previous block
rem Process current block: separate lines at "$" character
for /F "tokens=1* delims=$" %%a in ("!thisBlock!") do (
if defined thisBlock (
if defined thisBlock echo !thisBlock!
Previous program is not efficient because it read the same data already processed every time it needs to read the next block, but it is an example of how to do it. This method can be modified in order to read the file just one time.