Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I am making a memory game in batch for fun and came upon a problem. I had a high score's file for player scores and no mater what file type i used it could be read and edited.

I am wondering if it is possible for a .bat file to store data within itself permanently, even after i close the program. So when open it again the data will still be there. Is this possible?

Thank-you in advance guys.

share|improve this question
up vote 3 down vote accepted
@echo off
for /f "tokens=1 delims=:" %%D in ('findstr /R /N "end_of_batch_label" "%~f0"' ) do set end_batch=%%D

echo -- HERE WE MAKE A NEW SELF CONTAINED RECORD --

echo echo data entry 4^>^>"%~f0"
echo(>>"%~f0"
echo data entry ^4>>"%~f0"

echo -- HERE STARTS PRINTING OF SELF CONTAINED DATA --
type "%~f0" | more +%end_batch%
exit /b 0


:end_of_batch_label

data entry 1
data entry 2


data entry 3

Of course it is.Try the code above.

share|improve this answer
    
Thank-you, but can you explain this. I am relatively new to programming and well this is a little beyond me. – Calder Hutchins May 27 '13 at 18:26
    
The data entries starts after :end_of_batch_label.With findstr /R /N "end_of_batch_label" "%~f0" we can find all lined that contains end_of_batch_label and putting this command in FOR /F we can extract the last line of these.With more +number we can print the content of the file after the pointed line.Hope this will help... – npocmaka May 27 '13 at 18:29
    
Is it possible to save a players score in in a batch game in the .bat file then call the data? Also what does "%~f0" and more +%end_batch% do? – Calder Hutchins May 27 '13 at 18:32
    
"%~f0" is a special parameter that will hold the path to batch file (unless shift command is used) .` +%end_batch% ` is a parameter passed to the MORE command (after the line where end_of_batch_label is found and the number is assigned to end_batch).E.g type some_file|more +5 will print all content of some_file after the 5th line. – npocmaka May 27 '13 at 18:35
    
Ok thank-you. I will experiment with this :) – Calder Hutchins May 27 '13 at 18:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.