Re: Newbie question about regular expression



Cameron Laird wrote:
How does the
if { [file exists $file] && [file readable $file] } {
...
you appear to have in mind not meet your requirements as a
"[c]heck if file exists and is readable"? It appears to me
that this fragment exactly fixes one of the things you say
you don't know how to fix.

Of course, he's better off doing that by trying to open the file for
reading, and catching the error when that fails. It's simpler, it's more
reliable (since [file readable] doesn't take into account all access
control schemes ever invented) and it doesn't have race conditions.

if {[catch {open $file} fd]} {
# File could not be opened; error message in $fd
} else {
# File exists, was readable, and is now open for business!
}

Donal.
.


Quantcast