in reply to Re: Skipping files in a directory
in thread Skipping files in a directory

++ccn as it is obviously much better to check for the existence of a directory before trying to open it and warn on failure

Replies are listed 'Best First'.
Re^3: Skipping files in a directory
by moritz (Cardinal) on Dec 11, 2008 at 11:58 UTC
    as it is obviously much better to check for the existence of a directory before trying to open it and warn on failure

    That might be OK here, but in the general case it is not, because of race conditions. If you check for the existence of a directory, and then open it, it might be deleted by another process between these two operations.

    Thus you have to do the error checking anyway, and don't gain anything by another call to stat (which most file test ops do).

    That's why the general philosophy with file access and IO is "try and see if it worked", not "first test if it might work, and then try".

Re^3: Skipping files in a directory
by anand_perl (Novice) on Dec 11, 2008 at 11:53 UTC

    Thanks a lot svenXY and ccn