Yes, removing elements from dirs is part of the os.walk API, but removing items from a list object while at the same time iterating over that list object is not healthy. So, iterate over a *copy* of the list, and remove items from the *original* list.