Open latest folder and read file


I have a workflow which downloads the attachment from mail, and saves it in a new folder everyday.
Now i need to open the folder that is created today and read the data in the file.

(need to open the current day’s folder and read the file). Please help me with folder opening

Thanks in advance

Hi @Vivek_Karuppusamy,

  1. Directory.GetFiles(“path”) - will return all the files in that path.
  2. Use For Each to loop through.
  3. Inside for each, use Path.GetFileNameWithoutExtension(fullPath) to get file name.
  4. Get the Date from File name using regex or split function
  5. Check the Date is equal to current date or not
  6. If yes, Proceed to read the file.


1 Like

Hi @Vivek_Karuppusamy,

if you want to build the folder name you can format it like that :

TodayFolderName = "Settlement - " & DateTime.Now.ToString("ddMMyyyy")




If someone else creating the folder then you can get the directories created today using the below query,

Directory.GetDirectories("yourdirectorypath").[Select](Function(d) New DirectoryInfo(d)).Where(Function(d) d.CreationTime.Date.Equals(Datetime.Now.Date)).ToList()

If you want to get the directory based on modified time, then change the “CreationTime” to “LastWriteTime”.

If your bot only creating the folder and it will be in the same naming format then we can go with @Boaepa post in this thread.

1 Like

Thanks @kadiravan_kalidoss @sarathi125 @Boaepa.

Many thanks for your valuable suggestions. :slight_smile:

im unable to read the txt file from the location, as im getting the aggregate Exception.
image .

. i need to copy the data from file and mail it to an user.

Hi @Vivek_Karuppusamy,

If you are getting aggregate exception, then it means the file is not available there.
Check whether the file available in the folder where you are trying to read it from the code.

Print the file path from the code and check the same.

Hi @sarathi125

Thanks for the immediate response.

There is a file available in the folder

And the file path is right when i print

But still i cant find a way to read the file in the location

In the message box we have the folder path alone, not the file path. File name missing here. So please check that.

1 Like

Thanks @sarathi125.

I have fixed the file path as you suggested.

Used the below expression to fix

Directory.GetFiles(“C:\Users\XXXXX\Documents\UiPath\Settlement_Report\Settlement Report\Settlement - ” & DateTime.Now.ToString(“ddMMyyyy”) ,“*.txt”,SearchOption.AllDirectories).OrderByDescending(Function(d) New FileInfo(d).CreationTime).ToList()

Now i have to read the file using notepad ++ due to format issue. I tried read text activity and start process activity, but couldn’t achieve what i need.

Why you need to read it using notepad++ any specific reason for that… And start which process based on which condition?

Due to format issue.

Format when opened in notepad++

Format when opened in notepad

That does not matter if you want to read the text alone form that file, Please confirm what you are trying to read from this file and what you have to do further with that

I want to open the file in the folder, copy the data and email to a user.

These are the steps i need to do

Okay, so you can read the text file using read text file activity, then split it with Environment.NewLine. After that in your Send Mail, make that as html mail body and form this string with
to form the same table as you shown in the notepad++ output.

Thanks. Will try that and let you know how it goes :slight_smile:

Hello @sarathi125 ,

I have fixed it as below image

and it is working fine :slight_smile:

For the format i had to change the default font setting of outlook. and had to uncheck the isBodyHTML in email activity

Thanks for you Valuable suggestions

1 Like