Script - sorting before merge

We are importing pdf pages from SAP and after we merge to create one document. We discovered that during the printing process from SAP to pd, some documents are not sorting correctly. How can I manage the sorting issue by using a script to sort based to name or time ?
Thnaks for your help


they documents will get merged in the order they finish getting converted.
Since some documents take longer than other to convert, this isn't necessarily the order in which they were originally printed. Adding a timeout between the print jobs will usually solve the issue.

Best regards