# Last saved file

**URL:** <https://forum.uipath.com/t/last-saved-file/508345>\
**Category:** Studio\
**Tags:** outlook, email, folders, question, studio, mail, excel, activities\
**Created:** [January 17, 2023, 9:55pm UTC](https://forum.uipath.com/t/last-saved-file/508345 "2023-01-17T21:55:37Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![khaled\_emad](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/khaled_emad/32/274207_2.png) [@khaled\_emad](https://forum.uipath.com/u/khaled_emad)\
**Post date:** [January 17, 2023, 9:55pm UTC](https://forum.uipath.com/t/last-saved-file/508345/1 "2023-01-17T21:55:37Z")

</div>

Hello  
I an downloading attachments from outlook to a specific folder and I need to edit them then re send an email with the attachment  
How cab I send the latest excel sheet saved in the folder as an email (latest by date)

thanks

---

<div class="post-metadata">

**Author:** ![mahmoud.zaky](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/mahmoud.zaky/32/301869_2.png) [@mahmoud.zaky](https://forum.uipath.com/u/mahmoud.zaky)\
**Post date:** [January 17, 2023, 9:59pm UTC](https://forum.uipath.com/t/last-saved-file/508345/2 "2023-01-17T21:59:53Z")

</div>

Hi @khaled_emad,  
You can use For Each File in Folder Activity as below:  
 ![image](https://global.discourse-cdn.com/uipath/original/4X/7/0/3/70373042f1387378930f94048309addd2c00d880.png)

and if you want to wait till file be downloaded first you can use (Wait for Download) Activity it will wait till file added to download folder location  
Please check and update us if you still have issue 🙂

---

<div class="post-metadata">

**Author:** ![khaled\_emad](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/khaled_emad/32/274207_2.png) [@khaled\_emad](https://forum.uipath.com/u/khaled_emad)\
**Post date:** [January 18, 2023, 5:04am UTC](https://forum.uipath.com/t/last-saved-file/508345/3 "2023-01-18T05:04:43Z")

</div>

thank you man but is there another way than using for each file in folder ?

---

<div class="post-metadata">

**Author:** ![mahmoud.zaky](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/mahmoud.zaky/32/301869_2.png) [@mahmoud.zaky](https://forum.uipath.com/u/mahmoud.zaky)\
**Post date:** [January 18, 2023, 9:07am UTC](https://forum.uipath.com/t/last-saved-file/508345/4 "2023-01-18T09:07:46Z")

</div>

You can use the second option in my comment ( Wait for Download ) activity try it and update us if you still have issue.

---

<div class="post-metadata">

**Author:** ![Jakub\_Modrzewski](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/jakub_modrzewski/32/209692_2.png) [@Jakub\_Modrzewski](https://forum.uipath.com/u/Jakub_Modrzewski)\
**Post date:** [January 18, 2023, 9:46am UTC](https://forum.uipath.com/t/last-saved-file/508345/5 "2023-01-18T09:46:56Z")

</div>

are you saving multiple attachments from outlook to a folder then you process it but you want to send further by mail just the one most recently saved (latest)?  
You could make int32 variable as counter which would increase with each downloaded attachment, add the counter to attachment name during saving then when sending out mail you can attach only the attachment that includes your counter in name.

Would that work for you?

![image](https://global.discourse-cdn.com/uipath/original/4X/a/7/9/a79cf371ecfc0cfa8aab0d2e017f2618f9ca4e54.png)

---

<div class="post-metadata">

**Author:** ![khaled\_emad](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/khaled_emad/32/274207_2.png) [@khaled\_emad](https://forum.uipath.com/u/khaled_emad)\
**Post date:** [January 18, 2023, 10:09am UTC](https://forum.uipath.com/t/last-saved-file/508345/6 "2023-01-18T10:09:06Z")

</div>

Actually I am downloading excel sheet from email to a folder edit it and resend it  
Once I download another sheet from another email to the same folder location, the folder now will have 2 sheets I need to email the last 1 downloaded

---

<div class="post-metadata">

**Author:** ![mahmoud.zaky](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/mahmoud.zaky/32/301869_2.png) [@mahmoud.zaky](https://forum.uipath.com/u/mahmoud.zaky)\
**Post date:** [January 18, 2023, 11:32am UTC](https://forum.uipath.com/t/last-saved-file/508345/7 "2023-01-18T11:32:37Z")

</div>

@khaled_emad please check below solution and update us if you still face issue.

> [@How to get latest file in folder using uipath](https://forum.uipath.com/t/how-to-get-latest-file-in-folder-using-uipath/171626/5):
>
> this expression would get you the latest file str\_filepath = Directory.GetFiles(yourfolder\_path,“\*.txt”).OrderByDescending(Function(d) New FileInfo(d).CreationTime).Tolist(0) Cheers @thima

---

<div class="post-metadata">

**Author:** ![Jakub\_Modrzewski](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/jakub_modrzewski/32/209692_2.png) [@Jakub\_Modrzewski](https://forum.uipath.com/u/Jakub_Modrzewski)\
**Post date:** [January 18, 2023, 11:37am UTC](https://forum.uipath.com/t/last-saved-file/508345/8 "2023-01-18T11:37:25Z")

</div>

in a loop save your attachment and create a variable:

 ![image](https://global.discourse-cdn.com/uipath/original/4X/4/7/b/47b152a938b346fcbfe910fa63e4167ba2a0bf04.png)

refer to the variable when processing excel:

![image](https://global.discourse-cdn.com/uipath/original/4X/1/b/9/1b93f6ba38b3eab838285195029eaea4fcdb5be8.png)

finally refer to the same variable when sending it out

![image](https://global.discourse-cdn.com/uipath/original/4X/9/2/0/92027bb2c0b82876952dab35e45c8fb1b9b8306d.png)

each loop will work only with currently downloaded file, even though there’s more than one in a fodler.
