Fix filelisting infinite loops

Related to #11804 but not sure it fixes it entirely