Expression for Directory.GetFiles

I am trying to process specific files from a folder using assign activity but it does not work
Can anyone please help me with this issue?
Below are the screenshots
image


Hi,

Unfortunately, GetFiles doesn’t support regex filter as the following document.

Can you try to use LINQ as the following, for example.

 System.IO.Directory.GetFiles(FilePaths1).Where(Function(f) System.Text.RegularExpressions.Regex.IsMatch(System.IO.Path.GetFileName(f),"(PAN|CHEQUE|GST).*.pdf|jpeg$")).ToArray

Regards,

2 Likes

@Yoichi Thanks your solution works but could u please tell me why did u use the above expression?

Hi,

Hope the following helps you.

System.IO.Directory.GetFiles(FilePaths1)

means to return all files in FilePaths1 folder.

.Where(Function(f) 

This means iterate the above files and filter out false item which the following expression returns

System.Text.RegularExpressions.Regex.IsMatch(System.IO.Path.GetFileName(f),"(PAN|CHEQUE|GST).*.pdf|jpeg$")).ToArray

This return true if the filename matches the regex pattern.
note: System.IO.Path.GetFileName returns just filename without directory.

As a result, we cam get files as if it were to use GetFiles with regex pattern.

Regards,

2 Likes

@Yoichi thanks

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