Reputation: 3
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
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
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