Separated out handling of the file/directory from the scanning of the directory