Intelligently collapse a directory structure to one directory.