Check if directory exists, before accessing it

Fixes #1