Extracting Dynamic FileName into a Variable to Write into Excel

Hi all,

I am saving an attachment from an email into a folder and then need to take that new file and insert it into a variable to use in a write cell activity. I can access the file name through Item.ToString in a ForEach but am having trouble using Regex or Split methods to extract the filename into a variable to be able to write that variable to excel.

For example: "C:\Users\ () \Documents\UiPath\ () \ (*) \ () \ ‘FileName’.

Hi can you please be more specific.

Thanks

Yes,

Each morning I receive an email with an HTML attachment. I am able to save that attachment into a folder, but then I need to pull the saved file name, for example, “DailyReport11/18/2019.html” into a variable so that I can input the file name into an excel spreadsheet. The attachment name is Dynamic so I am trying to either use Regex to get the string or delimit the file path with “” . In my For Each HTML Attachment the ‘Item’ is the file path. Hope this helps some.

hi @Ltanksley,

use the DIrectory.GetFiles(“FolderPath”) to get the all filename in the folder and run a for each loop on the files you get and then use Path.GetFileNameWithoutExtension(file) to get the files names without extensions.

Happy Learning :slight_smile:
Regards,
Achal Sharma

I was unfamiliar with Path.GetFileNameWithoutExtension, but that solved my problem. Thank you very much.

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