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!
Anil_G
(Anil Gorthi)
May 2, 2024, 4:30am
2
@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
Yoichi
(Yoichi)
May 2, 2024, 4:33am
3
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,