22

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

Drew
  • 75,699
  • 9
  • 109
  • 225
ideasman42
  • 8,375
  • 1
  • 28
  • 105

2 Answers2

36

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.

JeanPierre
  • 7,323
  • 1
  • 18
  • 37
15

file-directory-p is your friend.

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

Harald Hanche-Olsen
  • 2,401
  • 12
  • 15