Fix bug when directory does not exist