If you're using windows, just use the search in windows explorer and search for a full stop .
The results are every subfolder and file in that directory, just copy paste what you want out, i.e. all the files
Any script needs to search for all items in subfolders, and then either perform a move command on everything to the base directory, or rename all files removing all subfolders from their 'long' names. Same thing, just two functions.
My Linux commands aren't that great, but I found a few posts that might help.
If you are on Linux you can run find . -type f -exec mv {} . \;
That would find every file below the current folder you are in and move it to where you are currently located.
Then you could run find . -type d -empty -exec rm -rf {} \; to delete all empty directories.You might need to run it a few times if a lot of empty directories are nested.
To sort the files this is a bash script that I wrote and have used for years.