3 levels of Loops to get individual file names in a selected folder

Hello, I need help in looping through a folder that contains two (2) other sub-folders to get a file.

  • Then attach the file to an email
  • Copy the file name and paste in the subject area field of an email.
  • Get the email address from the second folder name, copy and paste in the TO field
  • Add a few line of text in the body of the mail.
  • Add an email address in the CC field
  • Send

I have added the below flowchart to describe what I want to achieve

Loop through three folders, Attach file, send email Flowchart - RPA.pdf (305.9 KB)

Hi there @Peter_Chibueze

The emailing part is easy and can be built with logic as required. Use any reviewed Uipath Go component or microsoft O365 inbuilt activites.

For getting ‘all’ files from one directory or sub-directories here is the Syntax - Directory.GetFiles(targetDirectory, "*.txt", SearchOption.AllDirectories) in an assign statement which has the accepting variable as an array.

*.txt can be replaced by any file-type you want and if you want all file types to be iterated through then you can keep only ‘**’ for the purpose.

If you want only the sub-folders then you can use the following code - Directory.GetDirectories("yourParentFolderPath") and the resulting array elements will have the full path of the two or more sub-folders that you have in the parent folder. Then subsequently you can iterate through them using Directory.GetFiles("TheArrayItem1or2")

Try and revert if you face any issues.

Regards :wink:

Thanks Raghavendraprasad, I have tried it but i face some issues. It didn’t see the path

1 Like

I can see in the error that there are no files in the given directory - so put your invoices with some unique naming system (like it should contain wither the reference ID or something through which you can get it in the conditional statement, that should work)

Regards :slight_smile:

1 Like

@Peter_Chibueze

Thank you for your inquiry.

The debuggin is as follows:

  • Assign activity { this will contain a list of pdfs} Right ? :slight_smile:
    * The assign folder is different than the one in assign ***Here is the error***

Please upload the xaml or take a good look on the assigned folder

Regards,


Don’t forget to like us :heartpulse:
Happy Automation! :sunglasses:

1 Like

Great!.. I’ve been able to display all the file names in the folder

Now what I want to do is to attach all the files in the folder to gmail so that I can send.

Please how do I do that?

This is my workflow below. I don’t know why I’m getting that issue.

Please assist