in reply to Re: directory exists
in thread directory exists

Isn't testing for -e and -d redundant? -d includes a -e test.

Replies are listed 'Best First'.
Re^3: directory exists
by Fletch (Bishop) on Jun 03, 2005 at 02:53 UTC

    Yup. Underneath it calls stat(2), which would return ENOENT if it doesn't exist (file or directory). -d goes on to use the returned struct stat* to check if it's a directory or not.

    --
    We're looking for people in ATL

Re^3: directory exists
by Zaxo (Archbishop) on Jun 03, 2005 at 03:19 UTC

    Yes. I'd use a test like this in real code, and I guess it got into my recommendation:

    is_dir { -e shift() ? -d _ ? 1 : 0 : undef; }
    With that I can test truth to see if there is a directory of that name, or defined to see if the name is in use.

    After Compline,
    Zaxo

      Even that's redundant. The -d function by itself DWYM, and returns undef if the stat fails, false if the file exists but is not a directory.