Properly handles directories.