Read file with changing date and time

Hi all,
My doubt is in my folder I have files with today’s date and system time I need to read that particular file. How to do that.

Can you please help

@hanviprebday ,
Hey do you want to read all the files one by one in the particular folder?


Can you share an example name?

My file name is 08-06-2023-17-08-23 so here everytime I run the bot the time will be different so I want to read that read the last saved file in that folder

@hanviprebday ,
Please use this in Assign Activity
File(String Variable ) =

Directory.GetFiles("FolderPath","*.xlsx").OrderByDescending(Function(d) New FileInfo(d).CreationTime).ToList(0)

Here you will get the Latest file
Note : I have assumed that the file is .xlsx if not please change it accordingly

Hi @hanviprebday

As long as you don’t have the exact data, which contains the date & system time of the file, it’s not possible to exactly pinpoint the file for processing.

You can consider 1 of these 2 approaches:

→ Try to read all the files which starts with today’s date & determine the file based on the data which is available inside or any other anchor factor. This approach will process only today’s files. If you run the same process tomorrow, you won’t be able to fetch yesterday’s files.

→ Fetch the latest file based on the modification factor. The following query will give you the most recently modified file.

recentFile = Directory.GetFiles("C:\YourDirectoryPath")
    .OrderByDescending(Function(f) New FileInfo(f).LastWriteTime)

Hope this helps,
Best Regards.

Use below one

strFilePath = Directory.GetFiles(yourfolder_path,“*.txt”).OrderByDescending(Function(d) New FileInfo(d).CreationTime).Tolist(0)

If you want to change the file extension Replace txt with your extension like .pdf, .xlsx,etc…

1 Like

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