Sort and validate today's date

Hi all, I need to go to a folder, sort the files by date modified and locate the current date file in the folder of type .txt. If the file is available then need to validate that file contains today’s date in format nameoffile_yyyymmdd.txt. Once we have validated the correct file then need to open it with notepad.

Please advise.

Hi @Anived_Mishra

You can try this condition in if activity

Directory.GetFiles(folderpath,"*.txt").Where(Function (m) System.Text.RegularExpressions.Regex.IsMatch(Path.GetFileName(m),".*_"+Now.ToString(yyyyMMdd)+".txt")=True).Count<>0

If this is true

U can get the file path via assign activity

Filepath= Directory.GetFiles(folderpath,"*.txt").Where(Function (m) System.Text.RegularExpressions.Regex.IsMatch(Path.GetFileName(m),".*_"+Now.ToString(yyyyMMdd)+".txt")=True)(0)

Try this

Thanks and Regards
Nived N

@Anived_Mishra,

This will give your the expected file names as a List(Of FileInfo)

Directory.GetFiles("C:\Test", "*.*", SearchOption.AllDirectories).[Select](Function(f) New FileInfo(f)).Where(Function(f) (f.Name.Contains(DateTime.Now.Date.ToString("yyyyMMdd"))) And (f.Extension.Equals(".txt")) And ((DateTime.Now - f.LastWriteTime).Days=0)).ToList()

Thank You. Will try.

Thank you, will try and let you know.