Move all subfolder files to the current / selected folder (Flatten folders) (Unpack folders)

I modified the topic, similar to this script:
Command:Unpack folders with one step undoable - Buttons/Scripts - Directory Opus Resource Centre (dopus.com)
But there seems to be something wrong with this script.

Yes, I tried and tried some combinations, but it says that an error occurred.