Link to home
Start Free TrialLog in
Avatar of marcelofr
marcelofr

asked on

set an event on file creation

How do I set an event to start a procedure when a file appears in a directory? May I use wildcards on that filename?
Avatar of jjbyers
jjbyers

You'll have to have a timer that fires a method that first looks for the file and then have this method fire the event.
Sorry, Yes you can use wildcards witht the dir method.
Avatar of marcelofr

ASKER

I knew this... but there's no other way to do it?
I knew this... but there's no other way to do it?
Not that I know of. Sorry
Try looking at this code.  It watches a directory for any change.
http://www.mvps.org/vbnet/code/fileapi/watchedfolder.htm
if you are waiting for a file to appear within like 10 seconds  or less then i would use this code:

do until dir(fname)
doEvents    'so the computer doesn't freeze up and go slow
loop
call whatever

fname could be like "blank.txt" or "*.exe" that has wildcards.

or if you're trying to just monitor if a file is there over a long period of time, i would make a timer w/ an interval of about 5 sec. or whatever you think.  put this code in it:

if dir(fname) then call whatever
I think there should be some event for a new file in an event driven language on an event driven OS, I DON'T like active loops: they're too expensive to the cpu. I'm look at spenner suggestion which is closer to my needs, I hope...
spenner: I like your suggestion. Post an answer ans I'll give you the points.
ASKER CERTIFIED SOLUTION
Avatar of spenner
spenner

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial