Find and merge two pdf from different folders

Hi All,

I have a problem regarding merging .pdf files from different folders with the condition, that the five first characters in the filenames should match for the merging of the pdfs to happen?

So say that folder 1 contains:
candycane48837.pdf
jackhammer3382.pdf
watertunnel3994.pdf

Folder 2 contains:
candyhouse7765.pdf
jackhammer1129.pdf
waterdoor9949.pdf

How do I get the files to matching and then execute of the merging?
It would be extra good if the larger file always would be selected as the top one in the merged pdf. (The bigger file is always in folder 1)
Experienced users probably have an easy fix for this.
Thanks a lot in adavnce!

Hi,

Hope the following sample helps you.

Sample20220125-1.zip (110.8 KB)

Regards,

1 Like

Hi,

Thanks a lot for the help this far! I get an error in my dict = value formula.

Can you see what is wrong with my expression?

Thanks in advance!

Hi,

It seems missing . (dot) just before ToArray.
Can you also compare the following expression with yours?

dt = filesInFolder1.ToDictionary(Function(f) f,Function(f) filesInFolder2.Where(Function(f2) System.IO.Path.GetFileName(f2).Substring(0,5)=System.IO.Path.GetFileName(f).Substring(0,5)).ToArray())

Regards,

Hi,

I added the dot before ToArray and checked if your expression match mine, which it did. Now it´s giving a new error. Could it be that my variable type setting could be wrong? I´ve tried to use “string” an String (String), but neither did work.

Regards, Arthur

Hi,

It should be Dictionary<string,string[]> type.
I attached the sample project as zip file in my first post. Can you also check it?

Regards,

Hi,

Sorry, missed that you sent a project file. I´ll have a look at that! Thanks a lot for all the help. I´ll get back when I get it to work or I encounter a new problem.

Best regards, Arthur

Hi Yoichi!

Everything is working now. Big big thanks to you! :raised_hands:

Best regards,
Arthur

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.