How to write an email body with extracted multiple file names?

Hi all, after run the rpa, I only receive one file name shown in the email instead of 3 (as my file has 3 files in there). anything I missed? I created For each, FileName = path.GetFileNameWithoutExtension. In the Email part, Body section - “Hi, below are the file names” + FileName + “Thanks”

Hi ,
You will have to store the file names in text file using append line in for each and after the loop, read text file and store it in variable. Pass this variable in email body.
Or Store file names in list and pass variable using string.join method.

Hi @koolrc812

Please change the assign activity inside your for loop like this

FileName = FileName + “,” +path.GetFileNameWithoutExtension

This will append the filename already stored to the new filename that you are giving with a comma in between

Cheers

Hi im a beginner, any chance you could screen capture for the email body part? or I just leave my email body part as the code should be same as before? I added append line - FileName, Write to Filename - “AppendName.txt”, but the email still the same, only showing one name?

Are you using send email inside or outside of for each loop?

for each loop then outside email email

Hi @koolrc812

Instead of for each can you try this method,

getFiles = Directory.GetFiles(“Your path here”)

getFileName = getFiles.AsEnumerable().select(function(x) path.GetFileNameWithoutExtension(x)).tolist()

FileName = String.Join(“,”,getFileName)

Thanks!
StringJoin.xaml (7.2 KB)

Thanks. I have one more condition is that I need to add - .Split("“c).last as I only need to show whatever the name after _
So after I added .Split(”
"c).last , the email received only 1 file name as before. How to fix that?

Hi @koolrc812 ,

Could not understand your query. Can you share any example?

Thanks!

sorry I mean it works well with your code. All those file names show in the email. (my file name is 123456_234567-34545.txt) and shows perfectly 123456_234567-34545.txt in email
but I only want the file name show in my email as 234567-34545. (any words after “_”)

Hi @koolrc812 ,

Can you try this

getFileName = getFiles.AsEnumerable().select(function(x) path.GetFileNameWithoutExtension(x).Split("_"c)(1)).tolist()

Your output will be

234567-34545

Thanks!

Thanks heaps. It works!!!

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