Normalise directory names before aggregating files.

This fixes a bug where trailing slashes on directory names broke things.