Fix #15862 remove dirs in keep list when walk path

My thirst for knowledge as to why you code this like you did has nothing to do with your single line list comprehension :smile:

The gain in this use case is that you don't create another object. Right?

That's the information I'm after so I can make use of it when needed...