From .toArray toString

Hello all,

I am currently trying my hand at flowcharting and would like to read in different files and loop through them.
I have already received support in the community and have the following assigns to help me with this:

arrFiles=Directory.GetFiles(Path)
arrMask={“Test1.xlsx”, “Test2.xlsx”}
arrFilesFiltered=arrFiles.Where(Function (x) arrMask.Any(Function (f) x.Contains(f))).toArray
FileName=arrMask(IndexFile)

Taking the variable arrFilesFiltered into a for each loop, it reads the files.

However, I want to achieve this outside of the for each in the flowchart and to do this I have a counter that gives me the content from arrMask.

My problem is to adapt this function “arrFiles.Where(Function (x) arrMask.Any(Function (f) x.Contains(f))).toArray”.

My idea to replace it with “arrFiles.Where(Function (x) FileName.Any(Function (f) x.Contains(f))).toArray” does not work. If I understand it correctly, it is because of the .toArray, since FileName is a .toString, who can help me with this?

Hi @NHoe

Please give a try,

it will give the first content of the array

arrFiles.Where(Function (x) arrMask.Any(Function (f) x.Contains(f)))(0).tostring

for convert array to string

String.join(arrFiles.Where(",",Function (x) FileName.Any(Function (f) x.Contains(f))).toArray)

Thanks

1 Like

Hi @prasath_S


Thank you very much for your answer. For String.join(arrFiles.Where(",",Function (x) FileName.Any(Function (f) x.Contains(f))).toArray) I get this Error

Error

@NHoe

Please try this,

String.join(",",arrFiles.Where(Function(x) FileName.Any(Function(f) x.Contains(f))).toArray)

Thanks

Thank you, now there is no more error message.

However, my problem still exists.

I would like the function to use the path from arrFiles and the file name from arrMask. However, since I want to work without a For Each activity, the value from arrMask comes from a counter that increases after each run and thus outputs the position from the arrMask array.

With this function I get all the files from the path
String.join(",",arrFiles.Where(Function(x) FileName.Any(Function(f) x.Contains(f))).toArray)

@prasath_S Sorry, you had already presented me with the solution
arrFiles.Where(Function (x) arrMask.Any(Function (f) x.Contains(f))(IndexFile).tostring

1 Like

@NHoe Glad that helped :grinning: