In single page course elements users can choose to link from existing files from the course folder or to upload a file or to create a new html page.
In the last two cases, the files are created/uploaded in the root directory of the course folder. When adding images and other media in the html editor, those are uploaded to the same level as the html file, in this case also to the root of the course folder.
Which quickly leads to a big mess in the course folder.
The solution is to automatically create a folder when uploading a file to the course element or when creating a new html page. In that folder, the file is added and media files added later on via the HTML editor are also put into that folder.
E.g. when creating a file "info.html", the final structure in the course folder looks like this:
Care must be taken when a folder name does already exist. In that case the standard renaming service should be used (FileUtils.rename())