refactor the recursive listing of the image directory