Copy dirs so the remove() works correctly.

It is not legal to remove items form a list while iterating
thought the list.