Apropos nothing, here’s a working draft of a subroutine to create a dummy file with the exact size of the original. Works up to the Batch limit. Never more than 58 passes (I think!) and no use of goto.
The idea is simple enough: keep all the temp files that double in size until the power of two before or equal to the original file size is reached, and re-use them on the way down to fill in the remainder. But I found the logic hard to nail down… either that or my wits aren’t as sharp as they used to be.
Code: Select all
@echo off & setlocal enableextensions enabledelayedexpansion
(call;)
set fsize=%~z1
set /a %fsize% 2>nul || goto die
if %fsize% equ 0 goto die
<nul set /p "=#" >dummy.txt
set /a p2=1,p2x2=2 & set "stub="
echo(| cmd /v:on /q /c for /l %%l in (^) do if not defined stub (^
if %fsize% geq ^^!p2x2^^! (type dummy.txt ^>dummy-^^!p2^^!.txt ^& ^
type dummy-^^!p2^^!.txt ^>^>dummy.txt ^& ^
set /a p2*=2,p2x2=p2*2 ^>nul^) else set /a stub=fsize - p2 ^>nul^) ^
else if ^^!stub^^! gtr 0 (set /a p2/=2 ^>nul ^& ^
if ^^!stub^^! geq ^^!p2^^! (set /a stub-=p2 ^>nul ^& ^
type dummy-^^!p2^^!.txt ^>^>dummy.txt^)^) else exit 0
del "dummy-*.txt"
goto end
:die
2>&1 echo(unexpected end of program
(call)
:end
endlocal & goto :eof
Next phase is beautification, adding options, etc. But before I go further, I thought I’d post it here in case anyone can spot some obvious inefficiency in the code. Constructive criticism appreciated!
- SB