21

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

2 Answers 2

35

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.

15

file-directory-p is your friend.

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

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

Your Answer

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

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