Simplification of the control flow in listAllDirectory()