This is a small script written by DonMischo which I modified slightly to make it a bit more flexible. I added support for multiple image-formats, and it now asks you for the model name when running the script instead of having to edit the script manually each time.
Place the script in a folder, and your dataset of images sorted by one folder per concept, and those folders should all be in the same folder as the script. Like this:
Then run the script, and enter the name of your model. This name will be used as the prefix for the captioning. It should then generate a caption-file for each image, placed inside the folder for the concept. It will use the folder name for the concept as part of the caption.
Description
Image renaming script based on concept folders.
Read a bit about it here:
https://civitai.com/articles/3327#heading-19803