0

I am playing a alpha game which when crashes corrupts the saved game, so i created a batch file to back up my saved game.

@echo off

:A

REM deletes old backup

RMDIR /S /Q "backup location 1"

REM creates back up

xcopy "game location" "backup location 1" /e /i /q /r /y

REM adds time out for 300 seconds

timeout /t 300

REM deletes old backup

RMDIR /S /Q "backup location 2"

REM creates back up

xcopy "game location" "backup location 2" /e /i /q /r /y

REM adds time out for 300 seconds

timeout /t 300


REM Repeats 

Goto A

This works just fine but it always stars on the first back up. What I want to do is have it continue from the previous point of backing up. I created the following test file

@echo off
set point=a

echo The variable is "%point%"

if %point%==c (goto :a)
if %point%==a (goto :b)
if %point%==b (goto :c)


:a
Echo A
set point=a
echo The variable is now "%point%"
pause


:b

Echo B
set point=b
echo The variable is now "%point%"
Pause

:c

Echo C
set point=c
echo The variable is now "%point%"
Pause

When the file is restarted the point variable is the same.

Is it possible to have the set point= save the variable to the file for the next time it is run?

Can you please explain any code suggested, I can use google to research it myself and probably will to get a better understanding. But if it is too complicated I may not know what I am looking at to google it.

Thank you for any help

Phoenix830
  • 19
  • 4
  • For more persistent variables, you might want to use [setx](http://stackoverflow.com/questions/3803581/setting-a-system-environment-variable-from-a-windows-batch-file). Although in this particular case if it were me I'd just create a new backup folder each time (timestamped) and delete the oldest folder when necessary. – indiv Jul 17 '15 at 05:42

3 Answers3

0

In some versions of DOS you can use the /p argument on the set command to load contents of a file into the variable.

set /p point=<a.txt

Where a.txt contains the value you want to set the "point" variable to.

Paurian
  • 1,372
  • 10
  • 18
0

best way to "survive" for data is a file.

you can write a variable to a file with:

echo %variable%>filename.txt

and read it back with

set /p variable=<filename.txt

This works fine with a single line (for example one variable). This method can be extended for a few more lines. If you want to save many (or an unknown number of) lines, there are better methods.

Stephan
  • 53,940
  • 10
  • 58
  • 91
0

Thank you for the replies. I have not looked at the /p but will do for a future script I have planned.

For the requirement of this script thank you indiv. For some reason having them in a time stamped folder eluded (even thou I have used them before).

To have the desired effect with just one file I changed

xcopy "game location" "backup location 1" /e /i /q /r /y

to

xcopy "game location" "backup location %date:/=-% %time::=-%\" /e /i /q /r /y 

and had the one command repeat itself.

On a side not if using this method there will be an unlimited number of folders. is there a way to limit folders to a z amount and delete older ones? I am happy deleting older backups, I am just curious for future projects

Phoenix830
  • 19
  • 4