Page 1 of 1

Is it posibl to achieve Directory watcher event

Posted: 10 Sep 2009 23:21
by suhasmahajan85
Hello All,

Is it poossible to achieve directory watcher event through dos script

E.g - I have dir say A if some text file is comes in this directory the an event should get raised

like if a.txt file comes in dir A the test.batch file shoulde get run. And there is no fix time for a.txt it will come any time in dir A.

how can we achieve it through dos script.

Posted: 11 Sep 2009 09:41
by avery_larry
**UNTESTED**

Code: Select all

@echo off
set "watchdir=c:\tmp"
set "watchfile=notify.txt"
set "eventprog=c:\mybatchfile.cmd"
::Could use wildcards like set "watchfile=*.txt"

:loop
if exist "%watchdir%\%watchfile%" start "%eventprog%" cmd /c "%eventprog%"
ping -n 2 -w 800 127.0.0.1 >nul 2>nul
goto :loop
You can add /wait after the word start if you want to wait for the other program to finish before continuing.

Thanks avery_larry

Posted: 11 Sep 2009 23:03
by suhasmahajan85
Thank you avery_larry

I tested it , Its working fine only the thing is when I run batch file that dos window is appear can we hide it (Is it possible to run it at back end).