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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to check for a new file in a given directory? 1

Status
Not open for further replies.

HotMadras

Programmer
Apr 20, 2001
74
GB
The subject says it all really. I want to be able to trigger an event when a new file is discovered in a given directory. I have a VB program that's rather cumbersome and doesn't really suit the environment it's being used in that I'd like to port to tcl. It uses a timer to decide when to check for new files. I was hoping to be able to use something like fileevent instead, so that the reaction is as near instantaneous as possible.
 
Fileevent is really a socket or channel function. It doesn't do what you want ("Execute a script when a channel becomes readable or writable"). I would probably use "glob" and keep an old list to compare to the result. Bob Rashkin
rrashkin@csc.com
 
Thanks, I think I've come up with a routine that will do what you suggested. I presume I'll have to run it with some sort of timer, then?
 
Either that or based on events in your code when you would act on that information. Bob Rashkin
rrashkin@csc.com
 
Thanks for your replies. I think that, provided the overhead doesn't turn out to be too horrible, I'm going to use "after" to pause the application between checks. I have to poll the directory as I've got no other way of determining if something new has arrived.

Thanks again.
 
You might also want to check the Tcl'ers Wiki ( It has a page called, "directory notification package in Tcl," which has some interesting comments and suggestions regarding what you're trying to do. - Ken Jones, President, ken@avia-training.com
Avia Training and Consulting, 866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top