How to Merge the same name Pdf files

Hi Team,

I have PDF Files under root folder in sub folders with diffrent (Dynamic) names and i want to merge the PDF file based on matching case as below.

Input date like this

Root folder: Cnames
Sub folder: A

PDF FIles as below in A

ABC123_A1
ABC123

ZBC124_B2
ZBC124

Sub folder: B

PDF FIles as below in B

BCD124_C1
BCD124_C2
BCD124

Ouput Requirment Combine PDFs as this:

Create a new root folder like this: Cnamesmrged_Today date

Sub folder: A

PDF FIles as below

ABC123_A1 ’ i.,e ABC123_A1 + ABC123
ZBC124_B2

Sub folder: B

PDF FIles as below

BCD124_C1
BCD124_C2

@lakshman @Abhishek14 @Lahiru.Fernando

Hi …@VB_Tech_pro - This is a mini project …

We can take a look…but I am not clear on the requirements.

ABC123_A1, ABC123 = Here , Second file always has the first part matching with other file? and this file needs to be merged with file ending with _A1 ??

What if the second file has the name ABC345…so this needs to be separate right?

Also, How many files with the same name on it?

ABC123_A1, ABC123_A2, ABC123_B1 ==> This also needs to merged to one file right? if yes, what will be the merged file name?

In the below case, BCD124 file needs to be merged with C1 or C2? how do you determine the case?
BCD124_C1
BCD124_C2
BCD124

Hi Thanks for revert @prasath17

ABC123_A1, ABC123 = Here , Second file always has the first part matching with other file? and this file needs to be merged with file ending with _A1 ?? 1)>>>> Yes

2)>>>> Yes
3)>>>> like ABC123 is only 1 file, But ABC123_A1, ABC123_A2
4)>>>> No
ABC123_A1 +ABC123 = 1 pdf with file name as ABC123_A1 and pages will be ABC123_A1 is first page, ABC123 will be next page

ABC123_A2 +ABC123 = 1 pdf with rename as ABC123_A2 above sequence of merged pages
5)>>>> BCD124_C1 +BCD124 = 1 file, BCD124_C2 +BCD124 = 1 file

Hope my explanation is clear please assist