How do I perform an action that depends on a file’s arrival?

A. Users on hosts often transfer a file over an FTP link from another host and need to perform an action on the file when the file arrives. The following batch file, which requires the Microsoft Windows NT Resource Kit, lets you check for a file and run the file when it arrives.

if exist e:\upload\file.txt goto actionfile<br>
sleep 100<br>
goto filecheck<br>

This batch file checks for the file file.txt every 100 seconds. You might run into problems if the file is large and is still under construction when the batch file looks for the file (e.g., if the file is transferring over an FTP link and is still writing). To solve this problem, rename the file to itself, as the following command shows.

RENAME e:\upload\file.txt file.txt<br>
if not errorlevel 0 goto actionfile

The rename command generates an error message if the file doesn't exist or isn’t available to write to (e.g., because it is still being written to). The errorlevel is the same, but the error message changes, in case you want to distinguish between the two in the .bat file.

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.