batch-file

Save the same variable with different value twice in a txt file - Batch


I am new at batch programming. I want to save multiple values in a text file with the same variable. To be more clear here is my code:

@echo off
cls
set /a "num=0"
:start

echo %num%
set /a "num=num+1"
echo %num% > text.txt
goto start

What I need is that every time the number gets bigger and saved, the smaller numbers will remain saved. For example, now when %num% becomes "3", the number 3 will be saved in the text.txt file, but it will replace the previous number. Is there any solution?


Solution

  • Use the '>>' operator instead of '>'.