Create dynamic array lists

Hi Community ,

i am trying to segregate a list of file names based on the file substring. I have a reference type array and a list of filenames , i need to create a new array of just the file names of the type.

Input :
Array 1: Filenames list

filelist { C:\Test\Type1-20220410.pdf,
C:\Test\Type2-20220411.pdf,
C:\Test\Type3-20220412.pdf,
C:\Test\Type1-20220413.pdf,
C:\Test\Type2-20220414.pdf,
C:\Test\Type1-20220415.pdf,
C:\Test\Type2-20220416.pdf,
C:\Test\Type1-20220417.pdf,
C:\Test\Type1-20220418.pdf}

Array 2 : Reference List

ref{type1,type2}

Expected output :
Array 1:
Type1list{C:\Test\Type1-20220410.pdf,
C:\Test\Type1-20220413.pdf,
C:\Test\Type1-20220415.pdf,
C:\Test\Type1-20220417.pdf,
C:\Test\Type1-20220418.pdf}

Array 2
Type2list{C:\Test\Type2-20220411.pdf,
C:\Test\Type2-20220414.pdf,
C:\Test\Type2-20220416.pdf}

I want to dynamically create these arrays based on the reference list , if later type3 is added to the list . the code should be able to dynamically create 3 array lists .
Any help would be much appreciated , Thank you.

Hi @benjamin.9052 ,

Could you Check with the below Expression :

arrayGroupedFiles = (From d In Array1
Group d By k=Split(Path.GetFileNameWithoutExtension(d),"-")(0).ToLower Into grp=Group
Where Array2.Any(Function(x)k.Contains(x)) 
Select grp.ToArray).ToList

Here, Array1 & Array2 are of the type Array of String containing the input data & reference data and arrayGroupedFiles is a variable of the type List(Array Of String)

Visuals :
image

Let us know if this is not the expected output.

This is the expected output. This is helpful.

Thank you .

1 Like

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