How to test if a directory exists

As egreg said there is no direct test for directories. One possibility is if you are trying to read a file from within a directory then use \IfFileExists to check for its existence. If you are trying to write a file in the directory, then just try to open it for writing using \immediate\openout.

If you're not trying to read or write a file in the directory then the presence of the directory is unlikely to matter much (unless you just wish to do something different based on whether it is there or not) as you cannot enumerate directories without invoking the shell.