Placing images in a document via scripting

Hey guys, I am slowly getting interested into scripting (maybe because the stuff I do requires a lot of unnecessary repetition) But anyhow this is my question.

Does anyone know of a theory of how I can place a specific number of images into 1 document based on the name of a folder?

ex: Folder “X” contains 7 pictures / they all need to be placed into “x”.psd

so if I have 30 folders and 30 psd’s that have the name of that folder, I would like the script to just ask me where the main folder which contains the images so that it will place the respective images into the same name of the psd file.

The reason I need this is I have a multiple amount of PSD files that I need to place a certain number of pictures into (over 500) and I don’t mind loading the script if it means that the script will do this option for me (will save me 30-60 minutes per folder)

If anyone has a theory or an example script that they could share would GREATLY be appreciated. Thanks guys.:book: