Copyright © 2003-2011 by Prof.
Last modified Sun 4-Dec-2011 09:48:27
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
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
Please see "The Description and
the Index page
" for the conditions of usage and other such
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
@echo off & setlocal enableextensions
rem The log file. Employ the current script file's name, but use .log as the extension.
rem Get the last entry (the last line) of the log file.
if exist "%MyLogFile%" (
for /f "delims=" %%a in ('type "%MyLogFile%"') do set LastLine=%%a
rem Compare the last line with today's date.
if %errorlevel% EQU 0 (
echo Exiting: "%~f0" has already been run today
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