Windows IT Pro is the authoritative and independent resource for windows nt, windows 2000, windows 2003, windows xp. Features a collection of resources and magazines for windows IT professionals.
  
  
  Advanced Search 


January 09, 2000

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

RSS
Subscribe to Windows IT Pro | See More Resource Kit Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

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.

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

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
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.

End of Article



Reader Comments
is there any windows event that is fired when a file arrives in a directory

jyotsna November 13, 2003


You must log on before posting a comment.

If you don't have a username & password, please register now.




Top Viewed ArticlesView all articles
Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

How can I stop and start services from the command line?

...

PsExec

This freeware utility lets you execute processes on a remote system and redirect output to the local system. ...


Windows OSs Whitepapers Why SaaS is the Right Solution for Log Management

Related Events Check out our list of Free Email Newsletters!

Scripting eBooks Keeping Your Business Safe from Attack: Encryption and Certificate Services

Best Practices for Managing Linux and UNIX Servers

Building an Effective Reporting System

Related Scripting Resources Become a VIP member of the Windows IT Pro community!
Get it all with the VIP CD and VIP access. A $500+ value for only $279!

Subscribe to Windows IT Pro!
Solve your toughest technical problems with our experts and access 10,000 + articles online. 30% off

Monthly Online Pass - Only $5.95!
Get instant access to 10,000+ articles from Windows IT Pro Magazine!

TechNet Virtual Labs
Evaluate and test Microsoft's newest products.


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro Windows Dev Pro IT Job Hound ITTV
IT Library Technology Resource Directory Connected Home Windows Excavator Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 Copyright © 2008 Penton Media, Inc., All rights reserved. Terms and Use | Privacy Statement | Reprints and Licensing