Is it posibl to achieve Directory watcher event

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
suhasmahajan85
Posts: 5
Joined: 10 Sep 2009 22:53

Is it posibl to achieve Directory watcher event

#1 Post by suhasmahajan85 » 10 Sep 2009 23:21

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.

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

#2 Post by avery_larry » 11 Sep 2009 09:41

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

suhasmahajan85
Posts: 5
Joined: 10 Sep 2009 22:53

Thanks avery_larry

#3 Post by suhasmahajan85 » 11 Sep 2009 23:03

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

Post Reply