activities
latest
false
UiPath logo, featuring letters U and I in white
Productivity Activities
Last updated Nov 6, 2024

Move files to dedicated folders by type

About

Summary: Move new files in subfolders based on type (PNG, JPEG, XLSX, PPTX, PDF).

Applications: OneDrive

Description: Move files in dedicated folders based on the file type.

  • Identify the MimeType of the new File Created and move it to a specific folder.
    • Excel Files (.xlsx, .xls) – move to Excel folder

    • Docs Files (.docx) – move to Docs folder

    • Image Files (.png, .jpg ) – move to Images folder

    • PDF Files (.pdf) – move to PDF folder

  • If the document was not successfully moved, move it to an Unknown folder.

This example explains how to create a workflow that automatically moves new files to subfolders based on their type (PNG, JPEG, XLSX, PPTX, PDF). When a new file is created in OneDrive, the MimeType of the newly created file is identified, then the file is moved to a specific folder, based on its type. If the file wasn't successfully moved (if it isn't sorted into one of the above categories), it's moved to an Unknown folder.

This example presents Microsoft 365 activities such as File Created and Move File/Folder, as well as system activities such as If and Log Message.

Workflow

Tip: If you want to save time, use the Move Files to Dedicated Folders by Type template in Studio Web to build this workflow.
  1. Open Studio Web and create a new project.
  2. For How to start the automation select Event based, then select the Microsoft 365 File Created trigger activity.
  3. In the trigger activity:
    1. Set up your Microsoft OneDrive & SharePoint connection.
    2. Set the In Location field. For example, select one of your OneDrive folders.


  4. Add an If activity. At this step, we want to identify the MimeType of created files.
  5. In the activity, set the condition to identify image files:
    1. In the Condition builder widget, click the Plus icon to select Use variable.
    2. Select the output variable of the File Created trigger activity and filter down on Created file to find the MimeType property, then set the condition as contains image.
    3. In the expression editor, this condition looks like this: _out_NewFileCreated_1__Result.MimeType.Contains("image")


  6. Next, set Then, the activity to execute in case the condition is true (if the newly created file is an image).
    1. Add a Move File/Folder activity and configure it as follows:
      • File or folder to move - Select the Created file output variable.
      • Destination folder - Select the Images folder in your OneDrive.


  7. Next, add a Control: Set Variable Value activity. Control: Set Variable Value saves a value to use in later activities. Configure it as follows:
    • Value - set to True.
    • To - assign a FileMoved variable.


  8. Next, set more conditions, to identify different types of files. Repeat steps 4-7, but for each If condition, set the MimeType to contain text, sheet, pdf, and presentation. Select the Destination folder accordingly in the Move File/Folder activity.


  9. Finally, add an If activity to check if the created files have all been moved.
    1. Set the Condition as: FileMoved=true. This refers back to the Control: Set Variable Value activity set in step 7.
    2. For the Then activity, add a Log Message activity and configure it as follows:
      1. For the Message field, select the File Created output variable, then navigate to the Created file > FullName property.
      2. To complete the log message, add the following text: has been moved.


    3. Configure Else, the activity to execute in case the condition is false (e.g., if FileMoved=false):
      1. First, add a Log Message activity and configure it as follows:
        • For the Message field, select the File Created output variable, then navigate to the Created file > FullName property.
        • To complete the log message, add the following text: has not been moved. It will be moved to Unknown Folder.
      2. Next, add a Move File/Folder activity and configure it as follows:
        • File or folder to move - Select the Created file output variable.
        • Destination folder - Select the Unknown folder in your OneDrive.


  10. You're done and ready to run your project!
  • About
  • Workflow

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.