The scanning of folders and forming candidates is entirely outside Acrobat's control. Then the merging of files can be done with several entirely different APIs, but always on the model
Open first file
Insert second
Insert third
...
Save
Close
Repeat with next group of files
The choice of APIs largely depends on where you are starting, but the most obvious choice is OLE through the interapplication communication API.