I've seen how to check if a file exists (file-exists-p), but how to check if a directory exists?

2 Answers 2


From elisp manual:

-- Function: file-directory-p filename

This function returns ‘t’ if FILENAME is the name of an existing
 directory, ‘nil’ otherwise.

See also its docstring, with a note concerning symlinks:

(file-directory-p FILENAME)

Return t if FILENAME names an existing directory. Symbolic links to directories count as directories. See ‘file-symlink-p’ to distinguish symlinks.


file-directory-p is your friend.

Found using C-u C-h a directory RET and browsing the result.

  • @Drew Thanks, but I had copied the key sequence wrong. Fixed now. Commented Jul 25, 2017 at 20:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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