Nerd-cen-tric, adj. 1. Holding the view that technology is the center, object, and norm of all experience.

Creating a Zero Byte File

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.

Leave a Reply

You must be logged in to post a comment.

Nerdcentric Twitter Feed