Sort folders before replacing
This makes sure that even with multiple, nested projects, we get the shortest label possible into the categories.