How to read latest timestamp excel file

Hi friends,

In my dispatcher bot, I am saving excel file with timestamp like- Logs_10_14_2024_13:33:03 PM.

Now I want to read this excel file in performer bot. Can someone tells me how can we read downloaded file with this timestamp?

@Jeeru_venkat_Rao

Ideally it would be the latest saved file as well

Usw for each file in folder and then sort by created time

Cheers

@Jeeru_venkat_Rao,

If your file getting saved by dispatcher then you can add the file path directly to the queue item and access it from the performer.

Not using orchestrator. Using datatables only

@Jeeru_venkat_Rao,

If your Dispatcher and Performer going to be in same bot, use Global variable to store the file path. With this approach you don’t need to pass it through any arguments from workflow to workflow. It will be available in every workflow of your project.

I have 2 bots for dispatcher & performer.

Have to read excel in performer bot.

Are you using queues?

If so then the suggestion from @ashokkarale would be the way to go.

@Jeeru_venkat_Rao,

File System will not allow to use : in the file name.

So your file names not going to be - Logs_10_14_2024_13:33:03 PM. Choose another character to separate hh, mm, ss

@Jeeru_venkat_Rao,

Also 24 hours clock will not have AM/PM. Get the requirements correctly!

@Jeeru_venkat_Rao,

Here is simple logic to get latest file with timestamp in file name.
I have considered file name as below due to earlier highlighted flows.

Output:

The image shows a UiPath debug output panel indicating that the main file's debug has started successfully with no errors or warnings. (Captioned by AI)

LINQ:

latestFile = arrFiles.Select(Function(file) New With {  .FileName = file, .FileDateTime = DateTime.ParseExact(System.Text.RegularExpressions.Regex.Match(Path.GetFileName(file), "\d{2}_\d{2}_\d{4}_\d{2}_\d{2}_\d{2} (AM|PM)").Value, "MM_dd_yyyy_hh_mm_ss tt", System.Globalization.CultureInfo.InvariantCulture)}).OrderByDescending(Function(x) x.FileDateTime).FirstOrDefault().FileName

Thanks,
Ashok :slight_smile:

Thank you @ashokkarale.

I was running a code which give similar output like yours and its working now.

Directory.GetFiles( path,“*.xlsx”).OrderByDescending(Function(d) New FileInfo(d).CreationTime).Tolist(0)

I will try your code also

@Jeeru_venkat_Rao,

You don’t need to sort it while getting all the files as you need to sort it by File name timestamp not with the Creation time.

Just use this in first assign activity.

arrfiles=System.IO.Directory.GetFiles(path,"*.xlsx")

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