Tcl has no built-in support for file locking. Two or more programs can have a file open simultaneously. Usually, it a bad idea for multiple programs to try modifying a file simultaneously, but simultaneous reads aren't a problem.
You've got a couple of choices for implementing file locks. The best is to get the TclX extension. (It comes standard with the TclPro and ActiveTcl distributions.) It gives you
flock and
funlock commands for respectively locking and unlocking files. You could then test to see if a file is locked, and if so, try the next file in sequence, etc. But these TclX commands aren't supported on Windows.
For an all-Tcl solution (or one that works on Windows and/or Macintosh as well), you're going to have to simulate this by creating a lock file when your application is ready to open a file, and delete the lock file when it's finished with it. Then, your application would test for the existance of the appropriate lock file(s) before trying to open a file. The drawback of this approach is that you need to be very careful to clean up the lock file under all circumstances (anyplace your application could abort in response to an error, premature exits, as well as "ordinary" shutdown cases), otherwise you could be left with dangling lock files. - Ken Jones, President
Avia Training and Consulting
866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax