Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how can i "poll" a folder and grab files as they are created?

Status
Not open for further replies.

bookouri

IS-IT--Management
Feb 23, 2000
1,464
US
On a couple of "interfaces" I have, I create text files from our database, and i store them in folders for the vendor(s) applications. The vendor(s) applications "know" when a file appears and they grab the file and process it. How can i use VB/VBScript to "watch" a folder and do something whenever a user dumps a file there? Ive done this on "timers" before, but now I need to have the event happen immediately when the file is created.

any suggestions would be appreciated...
 
you need to read up on WMI async event notification.
you can registry for a file creation event. bascially the end result will be a function in your script will be called when the creation event occurs. it is quite a complicated process. i would recommend you buy this book which has a good section on how to accomplish the task
isbn 1-57870-260-7
 
this is a blocking method call.
not the best way to do it and not the async way i suggested in the last post but it might get you started

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\cimv2")
Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
("SELECT * FROM __InstanceCreationEvent WITHIN 10 WHERE Targetinstance ISA 'Win32_Directory'")
Do
Set objLatestEvent = colMonitoredEvents.NextEvent
Wscript.Echo "hello " & objLatestEvent.TargetInstance.Name
Loop
 
Thanks, I had no idea where to start looking, that should get me started....

 
beg your pardon, i didnt see the VB bit, defo go the api way chris13 suggests if you are going the VB way
 
thanks, Ive been looking at the WMI stuff. Ill take a look at the API stuff too. The API methods will probably be easier in this case...

 
Hi,
the API function is not as simple as wished, too. you'll need to parse FILE_NOTIFY_INFORMATION buffers to get your results. I used it synchronously and had no problems even when monitoring big trees like c:\, but asynchronous opration is possible, tool.









 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top