How to read a list of pdf names and merge files

Hi Community,

I have a folder containing similar pdf names, for example, BI2404100042_OR2403080040 and OR2403080040, and I want to merge these 2 files if they contain the same character.

As shown below, I would like to merge files no. 1 with no. 1 and no. 2 with no.2, respectively.

Would you please provide me some suggestions?
Thank you in advance!

@Wiragorn

when you say similar you mean the character count is similar in filenames?

if yes then Directory.GetFiles("FolderPath").GroupBy(function(x) x.Length).ToDictionary(function(x) x.Key,function(y) y.ToArray)

you can use above formula in for loop which gives you each group separately as one array

inside loop use merge files and pass the item directly currentitem.Value

cheers

HI,

How about the following sample?

dict = System.IO.Directory.GetFiles(System.Environment.CurrentDirectory,"*.pdf").GroupBy(Function(f) System.Text.RegularExpressions.Regex.Match(System.IO.Path.GetFileNameWithoutExtension(f),"[^_]*$").Value).ToDictionary(Function(g) g.Key,Function(g) g.ToArray())

Sample
Sample20240502-2.zip (311.1 KB)

Regards,