lundi 6 décembre 2021

Batch syntax for creating a file, putting a variable into it, and than reading the variable from it

I have the following code to create a file if it does not exist, creating a variable (hi), echo the variable into the file, and then read the text as a variable. If it does exist, it simply reads the text as a variable:

if exist hiscore.txt (
for /f "delims=" %%x in (hiscore.txt) do set /a hi=%%x
) else (
set /a hi=0
echo %hi%>"hiscore.txt"
for /f "delims=" %%x in (hiscore.txt) do set /a hi=%%x
)

if I create the file manually, and type 0 into it manually, it works. If I delete the file, and then run this, it says "Missing Operand" and echos "ECHO is off" into the file. What can I change?

Aucun commentaire:

Enregistrer un commentaire