2

I need to determine whether a certain path exists and points to a directory, like the -d test in the shell. I know about the filereadable() function, which does basically this for files:

filereadable({file})                    *filereadable()*
        The result is a Number, which is TRUE when a file with the
        name {file} exists, and can be read.  If {file} doesn't exist,
        or is a directory, the result is FALSE.  {file} is any
        expression, which is used as a String.
        If you don't care about the file being readable you can use
        |glob()|.

Is there an equivalent for directories?

7

You’re looking for the isdirectory() function:

isdirectory({directory})                *isdirectory()*
        The result is a Number, which is non-zero when a directory
        with the name {directory} exists.  If {directory} doesn't
        exist, or isn't a directory, the result is FALSE.  {directory}
        is any expression, which is used as a String.

Unlike filereadable(), this function doesn’t check whether the directory is readable; it only checks whether it exists. (Correspondingly, there isn’t a single built-in function to check whether a file exists without also checking that it’s readable. This answer demonstrates how to use the glob() function to do this kind of check.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.