studiox
2023.10
false
StudioX User Guide
Last updated Aug 7, 2024

Tutorial: Saving, Renaming, and Moving Attachments

In this tutorial, we will create an automation that saves the attachments to all the emails in an Outlook Search Folder to your computer, then moves the files to another folder on your computer and renames them by adding today's date to the file name. To rename the files, we will use a formula in the default Project Notebook available in StudioX.

We will create a project and start by adding a Use Desktop Outlook App activity to indicate the Outlook account to use. Inside this activity, we will add a For Each Email activity and then the common scenario Iterate through mail attachments to indicate that we want to save the attachments for each email and then process each file after it is saved. Iterating through each file in the folder where the attachments are saved, we will then add a Write Cell activity to copy the file name and edit the name in the Project Notebook, and a Move File activity to move the file with the updated name to another folder.

  1. Create two folders on your computer and a Search Folder in Outlook.
    1. Create two folders named In and Out at the root of the C: drive on your computer.
    2. Open Outlook, then right-click Search Folders in the Folder pane and select New Search Folder.
    3. In the New Search Folder window, select Create a custom Search Folder > Choose.
    4. In the Custom Search Folder window, enter "Last week's attachments" in the Name box and then select Criteria.
    5. In the Messages tab of the Search Folder Criteria window, from the drop-down menus next to Time select received and Last Week.
    6. From the More Choices tab, select Only items with and then one or more attachments from the adjacent drop-down menu.
    7. Click OK three times to close the windows and save the search folder.
  2. Set up a project.
  3. Add the Outlook account to the project.
    1. In the Activities panel, select the Mail tab, and then double-click Use Desktop Outlook App. The activity is added to the Designer panel.
    2. In the activity, the default email account is already selected in the Account field. If you want to use a different account, select it from the drop-down menu.
      In the Reference as field, leave the default value Outlook as the name by which to refer to the account in the automation.
  4. Iterate through the messages in the Outlook Search Folder.
    1. In the Activities panel, drag the For Each Email activity and drop it inside the Use Desktop Outlook App activity.
    2. In the For Each Email activity, click Plus docs image on the right side of the In emails from field, and then select Outlook > [Search Folders] > [Last week's attachments]. Your selection is displayed in the field as Last week's attachments.

      You have indicated that you want to iterate through the emails in the Outlook folder "Last week's attachments".



  5. Iterate through the mail attachments.
    1. Click Add activity docs image inside the For Each Email activity and then, in the search box at the top of the screen, select the common scenario Iterate through mail attachments.
    2. Browse to and select the In folder and click OK.

      Two activities are added to your project:

      • Save Email Attachments with CurrentMail selected for the Email field, indicating that the attachments from the current mail in the iteration should be saved to the In folder that is indicated by the C:\In selected in the Save to folder field.
      • For Each File In Folder with C:\In selected in the Folder field to indicate that you will iterate through the files in this folder.

        If you click Start to execute the automation now, the mail attachments are downloaded and saved to the In Folder.



  6. Rename and move the mail attachments to a different folder.
    1. In the Activities panel, select the Excel tab, then drag the Use Excel File activity and drop it inside the For Each File In Folder activity.
    2. Add a Write Cell activity inside the Use Excel File activity.
    3. In the Write Cell activity:
      • Click Plus docs image on the right side of the What to write field and then select CurrentFile > Full Name (includes full path) to indicate that we want to copy the full path of the current file in the iteration.
      • Click Plus docs image on the right side of the Where to write field and then select Notebook > File [Sheet] > FullFileName [Cell] to indicate that we want to paste the full path of the current file in the iteration to the FullFileName named cell in the File sheet of the Project Notebook.
    4. Click Notebook in the StudioX ribbon. In the Project_Notebook.xslx file, go to the File sheet, update the value in the named cell ReformattedFileName (B14) to the following: =FileNameNoExtension & "-" & YYYYMMDD & "." & FileExtension and save the file. This formula adds the current date at the end of the file name.
    5. In the Activities panel, select the File tab, then drag the Move File activity and drop it after the Write Cell activity inside For Each File In Folder.
    6. In the Move File activity:
      • Click Plus docs image on the right side of the From field and then select CurrentFile > Full Name (includes full path) to indicate the full path of the current file in the iteration.
      • Click Plus docs image on the right side of the To field and then select Text. In the Text Builder, enter C:\Out\ and then click Plus docs image on the right side of the window and select Notebook > File [Sheet] > ReformattedFileName [Cell]. The path in the Text Builder should look like this: C:\Out\[Notes] File!ReformattedFileName.
      • Make sure the Overwrite option is selected.
    7. Click Save in the Text Builder.


    8. Click Save in the StudioX ribbon to save the automation, then click Run to execute the automation.

      The attachments from each email in the Outlook Search Folder are saved to the In folder on the computer, then today's date is added to the name and they are moved to the Out folder.

Was this page helpful?

Get The Help You Need
Learning RPA - Automation Courses
UiPath Community Forum
Uipath Logo White
Trust and Security
© 2005-2024 UiPath. All rights reserved.