check if the directory exists first