Let's POWER Automate

From no-code to low-code

Menu
  • Expressions
  • Filters
  • General
  • Application specific solutions
    • Dataverse
    • Excel
    • Forms
    • Outlook
    • Planner
    • Power Apps
    • SharePoint
    • Teams
  • Triggers
  • Ready to use solutions
    • Approval Process Template
    • Task Delegation App
    • The Ultimate Power Automate expressions cheat sheet
    • Power Automate HTTP requests to SharePoint cheat sheet
    • Power Automate HTTP requests to Graph API cheat sheet
  • ABOUT ME
  • Get help with your flow
  • POWER PLATFORM SERVICES
Menu

How to split file name for further processing in Power Automate

Posted on June 13, 2021 by Tom

“The files attached to an email have always the same file name format: ID_Type_User, how can I split it in Power Automate to get all 3 pieces of the information?”


When you process files with Power Automate, the easiest way to add more information about the file is in the file name. You can define a format that will tell you the file type, the related ID, and much more. With a predefined naming convention it’s also much easier to process the files. It doesn’t matter if it’s from an email attachment, or uploaded using drag and drop by users. You don’t have to ask users to fill out the file properties, Power Automate will do it for you. And this post will show you how to do that.

Use the split(…) expression

The Power Automate expression you’ll use is split(…). This expression will split a string by predefined character and return an array with all the pieces. The first parameter is the text/string to split, the second one is the character. For example, let’s take a file name in format ID_Type_User: 1234_Contract_Tom.pdf.

split('<string>', '<character>')

split('1234_Contract_Tom.pdf', '_') will return an array ["1234","Contract","Tom.pdf"]

Or a real example to split a file name from an email attachment.

split(outputs('Get_Attachment_(V2)')?['body/name'],'_')
Power Automate split file name

Access the specific value

As already mentioned, the split(…) expression will produce an array. Following the example from above, you’ll get the array below. Each item in the array will be one part of the file name.

[
    "1234",
    "Contract",
    "Tom.pdf"
]

And because it’s an array, you can access each value by the index: [0], [1], [2]…

[
    "1234",             index [0] in the array
    "Contract",         index [1] in the array
    "Tom.pdf"           index [2] in the array
]

You can even add the index directly into the expression to get only the desired value.

split(outputs('Get_Attachment_(V2)')?['body/name'],'_')[0]  will give you 1234
split(outputs('Get_Attachment_(V2)')?['body/name'],'_')[1]  will give you Contract
split(outputs('Get_Attachment_(V2)')?['body/name'],'_')[2]  will give you Tom.pdf

Remove the file extension

You probably noticed, that the last part of the string contains also the file extension. To remove the file extension, use another split on the last item, this time by a dot. Take only the 1st value on index [0] from that split and use it for the 2nd split.

split(outputs('Get_Attachment_(V2)')?['body/name'],'.')[0] will give you 1234_Contract_Tom

split(split(outputs('Get_Attachment_(V2)')?['body/name'],'.')[0],'_')[2] will give you Tom

Summary

This post was using split(…) expression only to split file name with Power Automate, but it’s not the only use case. You can use the same approach to split any string in a flow, just make sure that the string has always the same format.

Additionally to the split(…) expression itself, it’s also good to understand the array it produces. Because it’s an array, you can access the values directly via their index. It always starts with 0 and goes up to the length of the array minus 1.


πŸš€ Master Power Automate

Join 2,000+ professionals getting actionable Power Automate tutorials, solutions, cheat sheets & tips every week.

No spam. Unsubscribe anytime.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

πŸš€ Master Power Automate

Join 2,000+ professionals getting actionable Power Automate tutorials, solutions, cheat sheets & tips every week.

No spam. Unsubscribe anytime.

Working on an Approval process?

Use the Approval Process Template and the Task Delegation App to skip the hard part and deploy a fully functional approval solution on a SharePoint list in minutes! And then the next one, and the next one...

Approval Template Preview ✨ Learn more ✨

Turn ideas into flows with ease!

Grab the complete Power Automate Cheat Sheet Bundleβ€”everything you need to master expressions, SharePoint HTTP calls, and Graph API in Power Automate.

Cheat Sheet Bundle Preview ✨ Get the Cheat Sheets

Didn't find what you were looking for?
Need to adjust a solution to fit your needs?
Or would you just like to get an assistance from somebody with thousands of hours of experience with Power Automate?

Power Automate blogs worth visiting

Damien Bird
Dennis (Expiscornovus)
Paul Murana

©2025 Let's POWER Automate | Theme by SuperbThemes