Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have some batch scripts which wait for files. The wait loop is done with the typical IF EXISTS loop:

:waitloop
IF EXISTS file.zip GOTO waitloopend
sleep.exe 60
goto waitloop
: waitloopend

I am looking for a more efficient way of waiting for files. Something like a waitfile.exe command which will block and wait until the file appears. Internally, it should use the FileSystemWatcher class to be able to exit as soon as the file appears.

In Linux I have my own Perl script which internally uses Inotify.

Do you know if there exists a tool like this?

share|improve this question
    
You cna probably safely reduce the waiting time to 1 second for quicker response. Checking for file existance isn't that much of a burden on the system if you do it once every second instead of once every minute. –  Joey Jun 21 '11 at 12:11
    
The files are in a remote file server (samba). Some time ago i had to increase the sleeping time from 5 to 60 seconds because of fileserver overload. I have dozens of processes waiting for files to appear in the fileserver. Probably i should be using some kind of IPC instead of polling... –  Francisco R Jun 21 '11 at 13:17
    
Ah, ok, SMB is an argument, especially the ancient version. SMB 2 did a lot to reduce latency problems, but afaik Sambe isn't there yet, despite it being 4 years old by now –  Joey Jun 21 '11 at 18:47

2 Answers 2

Does this help: How to monitor a folder and trigger a command-line action when a file is created or edited? ? - there's a .vbs file there that might solve your issue.

share|improve this answer

A typical file system monitor detects file creations and if the file will be created while the tool is active you will receive the event, but if you will start the tool with an already existing file, there will be no subsequent creation events and the tool will wait forever.

It looks like you need to implement a custom tool, which will first check if the file already exists and if not start monitoring for the file.

share|improve this answer
    
Thanks for your answer, but i'm asking for an already made tool, so "implement a custom tool" is not a valid answer, sorry. –  Francisco R Jun 24 '11 at 9:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.