This is a possible solution
To move files from the child to the toplevel directory:
find ! -name . -maxdepth 1 -type d | xargs -I {} sh -c "find {}/{} -maxdepth 1 | xargs -I [] echo \"mv [] {}\""
This works because if the child folder doesnt exists find would do nothing:
find foo4/foo4
find: 'foo4/foo4': No such file or directory
To remove reapted child directory
find ! -name . -maxdepth 1 -type d | xargs -I {} find {}/{} -type d -maxdepth 1 | xargs rmdir
I think it did what it was intended for. Disadvantage:
It shows many harmless errors.