Issue in picking up latest file from a folder based on ReGex

There are multiple files present in a folder, out of which I want to pick up the latest file with the name matching to a regular expression , and using below expression but it is throwing error . PFB the expression:
String.Join("", Directory.GetFiles(Directory_Path,“All request as of /\d{1,2}/\s/\d{1,2}/\s/\d{4}.xlsx”,SearchOption.AllDirectories).OrderByDescending(Function(d) New FileInfo(d).CreationTime).Take(1) )

but when I am removing the regex part it works fine , I want to use regex to ignore not required files.

String.Join("", Directory.GetFiles(Directory_Path,“All request as of *.xlsx”,SearchOption.AllDirectories).OrderByDescending(Function(d) New FileInfo(d).CreationTime).Take(1) )

Hi @Ritika_Singh

Just give it a try

Use For each file in folder

image

Regards
Sudharsan

Hi

This expression should be actually getting you the result you are expecting
May I know why do we need a separate Regex on this case and what error you are getting

Cheers @Ritika_Singh

@Ritika_Singh searchPattern

String

The search string to match against the names of files in path . This parameter can contain a combination of valid literal path and wildcard (* and ?) characters, but it doesn’t support regular expressions.

taken from docu link:

we could rewrite by
Assign Activity
Left: strFileName
Right:

(From fi in new DirectoryInfo(DirPath).getFiles(“All request as of*”)
Where Regex.IsMatch(fi.Name,YourRegexPattern)
Order by fi.CreationTime
Select s=fi.FullName).Last()

Hi @Palaniyappan ,

The error that I am getting is "cannot find part of the path " . I need to use regex as there are some other files with same name but have some words like rerun etc. at the end so I just want to ignore them , so i want to use regex. If I am using * then those files will also be picked up .

from the docu link shared with you above you can check that regex is not supported:

within this approach RegEx can be used