Introduction: Batch File That Only Runs Certain Code Upon First Use
Hello. It was hard to explain in the title, but basically what this does is makes a batch file run certain code, but it only runs it the first time the file is opened. It works by creating a text file and checking for it. This can be useful to make tutorials that only open the first time a user runs the file.
Step 1: Create the File
Pretty obvious. Just create a new file and make the file extension '.bat'
Now open it in an editor.
Step 2: The Code
Here is the code. In this example, it will tell a tutorial the first time the file is opened, but after that it'll just go straight to the main menu. NOTE: You'll probably want to put the batch file in a folder so it can create the text file in the folder as well. Just helps keep it organized.
if not exist first.txt goto tutorial
if exist first.txt goto mainmenu
echo This is the main menu. If this opened immediately when you ran this file, you've opened this file before.
echo don't delete this! >first.txt REM this line creates the file so next time
echo Welcome! This is your first time running this file! Next time you run this, you won't see this menu.