cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
nedwards87
Level: Powered On

Save email attachments based on attachment name

I am looking to create a flow that will save email attachments to specific folders based on their file names. I would like to set up an excel file or sharepoint list that will contain the information needed including the filename and the filepath where the file should be saved so that as i add additional filenames/folders, i dont have to modify the flow. 

So, if the attachment filename contains X0881 it would move it to a specific folder C:\data\881\

and if the filename contains X0904 it would move it to a specific folder C:\data\904\

and so on. 

 

Any thoughts?

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: Save email attachments based on attachment name

Hi @nedwards87 ,

 

If the files name are always in the same format, please try if the following way will work for you.

 

In this scenario, the file name will be the format likes “X0881Document”, I then get the key number 881 from the name and use it as the folder name. If a folder of name 881 already exists, the file will be created automatically, else, create the folder first, then create the file.

 

The function used in the Compose action:

 

substring(items('Apply_to_each')?['Name'],2,3)

 

 

 

An image for your reference:

1.PNG

 

Further, you could also try with what you’ve mentioned in your original post,, using an Excel or SharePoint list that contains the information needed including the filename, filepath. Then adding a condition to check if the attachment name contains the filename, if yes, create the file to the corresponding filepath.

 

Best regards,

Mabel

 

Community Support Team _ Mabel Mao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
Super User
Super User

Re: Save email attachments based on attachment name

You can do this fairly simply, although I highly recommend avoiding an Excel file due to the many Excel Connector restrictions. A Visual Explanation of Flow Logical Expressions can get you started down the right path.

Basically you need to create a logical expression to check the attachment names of received emails, and if and when the match is met, it dynamically creates the matching subdirectory, and saves the file with a matching name.

This Modify Dynamic Content Before Use in Flow thread has a very similar request. 

 

nedwards87
Level: Powered On

Re: Save email attachments based on attachment name

I have the logical expression down so that Flow can identify the email attachements based on the name, however, i am stuck on how to get flow to dynamically save the file to different folders based on theattachements filename. My initial though was to create a sharepoint list that contains the matching filenamename in one column and the folderpath where the file should be save in another column. 

Community Support Team
Community Support Team

Re: Save email attachments based on attachment name

Hi @nedwards87 ,

 

You may consider using Switch case in your flow.

 

If the file name contains X0881, then it goes to the action to create the file under folder  C:\data\881\.

If the file name contains X0904, then it goes to the action to create the file under folder C:\data\904\.

 

More details about Switch case for your reference:

https://flow.microsoft.com/en-us/blog/search-by-service/

 

Best regards,

Mabel

 

Community Support Team _ Mabel Mao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
nedwards87
Level: Powered On

Re: Save email attachments based on attachment name

This is how I currently have it configured but it is not ideal as we have more than 80 different files names right now and the case is limited to 27. The case method then requires cases within a case to get to 80. In the next few months we will be increasing to over 100 different filenames that the flow will need to process. This method is also extremely slow and when an email comes in with 8 attachments, it takes Flow about 10 seconds per attachment to process. 

Community Support Team
Community Support Team

Re: Save email attachments based on attachment name

Hi @nedwards87 ,

 

If the files name are always in the same format, please try if the following way will work for you.

 

In this scenario, the file name will be the format likes “X0881Document”, I then get the key number 881 from the name and use it as the folder name. If a folder of name 881 already exists, the file will be created automatically, else, create the folder first, then create the file.

 

The function used in the Compose action:

 

substring(items('Apply_to_each')?['Name'],2,3)

 

 

 

An image for your reference:

1.PNG

 

Further, you could also try with what you’ve mentioned in your original post,, using an Excel or SharePoint list that contains the information needed including the filename, filepath. Then adding a condition to check if the attachment name contains the filename, if yes, create the file to the corresponding filepath.

 

Best regards,

Mabel

 

Community Support Team _ Mabel Mao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

nedwards87
Level: Powered On

Re: Save email attachments based on attachment name

Thanks for the reply. I have adopted your first solution for the time being. I do have a question, how would you reference the sharepoint list and pull the correspoding column for the filename?

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

firstImage

Incoming: New and improved badges!

We've given our badges an overhaul and also added some brand new ones!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Power Automate Community Video Gallery!

Top Kudoed Authors (Last 30 Days)
Users online (5,497)