Zero Byte Files/Flags

This item was filled under [ Server ]

From time to time you need a method to create and test for the existence of a zero byte file in your scripting.  I use these files as flags, so that I know if an earlier prerequisite process completed successfully.

Creating the zero byte file is a simple process:

@echo off
echo.
echo – Check to see if the file is already present
echo.
if exist C:\somedirectory\flag.txt goto Halt
echo – Creating flag.txt
type nul>C:\somedirectory\flag.txt

:Halt
echo.
echo – Flag file already present, halting.

So now to check for the flag before completing your dependent process do an “if” statement similar to this:

@echo off
echo.
echo – Check for flag file
echo.
if not exist C:\somedirectory\flag.txt goto Halt
echo.
echo – Remove flag
echo.
del c:\somedirectory\flag.txt
echo.
echo – Do task
echo.
copy c:\somedirectory\somefile.exe \\someserver\someshare\somefile.exe 

:Halt
echo.
echo – Flag not present, stopping script 

Using this method you can set a flag during an earlier batch process and then check for that flag in a subsequent process.  Walla!  You can verify what you thought happened in an earlier script actually did.

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
Tagged with: [ ]
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Comment