1LEGODUDE13
1LEGODUDE13

Reputation: 3

Make a batch file say something only when opened for the first time

If it's possible, how do you get a batch file to only say something once? As in, only when it is opened for the first time?

Upvotes: 0

Views: 238

Answers (2)

foxidrive
foxidrive

Reputation: 41244

Here's a method - you can also add a path for the "firstrun.txt" file.

@echo off
if not exist "firstrun.txt" (
   echo This is the first time you have run this batch file...
   type nul >"firstrun.txt"
)

:: batch code goes here

Upvotes: 0

Aacini
Aacini

Reputation: 67216

Include this code wherever you want in your Batch file:

call :FirstTime 2>NUL
if errorlevel 1 (
   echo :FirstTime >> "%~F0"
   echo exit /B 0 >> "%~F0"

   echo This is the first time this file run!
)

Just BE SURE to end your Batch file with: goto :EOF

Upvotes: 2

Related Questions