URGENT: File exists

Lennart Augustsson lennart@augustsson.net
Sat, 03 Nov 2001 12:22:47 +0100

bracaman@box.sk wrote:

> I need to create a function that checks if a file exists. My intention is to do something like:
>  teste :: String -> Bool (Beeing the String the FilePath)
> I've tried to use openFile and catch functions, but i couldn't put it working. The purpose of this function
> is to test a file before trying to read it. Example:
> if (test "filepath") then readfile else fail

This kind of function, which tests the possibility of something in the world, is
generally bad.  The reason is that the things might change between the point
where yout test for a file being readable and the time when you actually read
it.  And then your program will fail anyway.
It's much better to make it work with the atomic readfile operation.

    -- Lennart