C:\_G\WWW\~ELISANET\INFO\tscmd180.html
<http://www.elisanet.fi/tsalmi/info/tscmd180.html>
Copyright © 2003- by Prof. Timo Salmi  
Last modified Mon 24-Dec-2018 10:39:21

 
Assorted NT/2000/XP/.. CMD.EXE Script Tricks
From the html version of the tscmd.zip 1cmdfaq.txt file
To the Description and the Index
 

This page is edited from the 1cmdfaq.txt faq-file contained in my tscmd.zip command line interface (CLI) collection. That zipped file has much additional material, including a number of detached .cmd script files. It is recommended that you also get the zipped version as a companion.

Please see "The Description and the Index page" for the conditions of usage and other such information.



180} I want to exit my script if it already has been run today.

Although not quite the same, this has some resemblance to avoiding multiple calls of a script with a lockfile as explained in Item #12.

  @echo off & setlocal enableextensions
  rem The log file. Employ the current script file's name, but use .log as the extension.
  set MyLogFile="%mytemp%\%~n0.log"
  rem Get the last entry (the last line) of the log file.
  set LastLine=
  if exist "%MyLogFile%" (
    for /f "delims=" %%a in ('type "%MyLogFile%"') do set LastLine=%%a
    )
  rem Compare the last line with today's date.
  echo.%LastLine%|findstr /c:"%date%">nul
  if %errorlevel% EQU 0 (
    echo Exiting: "%~f0" has already been run today
    echo %LastLine%
    goto :EOF)
  ::
  rem Whatever your script is otherwise designed to do.
  echo Do whatever
  ::
  rem Write into the log file the time of running this script.
  echo %date% %time%>>"%MyLogFile%"
  endlocal & goto :EOF

(If you have not set the mytemp environment variable, the root is indicated. For more study e.g. the logic of AssignTemp in Item #18.)

References/Comments:
  Google Groups Nov 26 2009, 8:04 pm

[Previous] [Next]

C:\_G\WWW\~ELISANET\INFO\tscmd180.html
C:\_G\WWW\~ELISANET\FTPCMD\TSALMI.CMD /tscmd180
http://www.elisanet.fi/tsalmi/info/tscmd180.html
file:///c:/_g/www/~elisanet/info/tscmd180.html