Corrected error handling for directories.