23

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

2 Answers 2

37

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. Commented Jul 25, 2017 at 20:10

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.