I often run into situations where I have directories that contain only one file, a subdirectory, with contain only one file, a subdirectory, and so on for a long chain, until I get to the interesting files. These situations come up when I have only part of a data set so the files that would be in other directories aren't there, and I find it annoying to deal with these long directory specifications. So, this challenge is to fix that by collapsing those one-entry directories into a single one.
For example, you should take this structure, where you have A/B/C/D/E in a direct line with no other branches:
and turn it into this one, with a single directory with the files that were at the end:
However, you should only moves files up if the directory above it has only one entry (which must be a subdirectory!). In this example, A/B/C has two subdirectories in it:
so the files in E should only move up into D. Otherwise, the files from the two branches in C would get mixed up with each other.