web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Parsing the name of at...
Power Automate
Answered

Parsing the name of attachments in a mail

(0) ShareShare
ReportReport
Posted on by 5

So, im building this flow, where i have a mail with several attachments. These attachments needs to be saved in a sharepoint folder structure, based on the attachement's name. The attachment names are the names of our employees. The folder structure is build like this, on the first level we have folders names A,B,C,D.....X. Beneath each of these there are one folder for each employee, where the foldername are the persons full name.

 

So i want the attachment called "John Doe.pdf" to be saved in this subfolder: "/J/John Doe/". The attachment "Sarah John.pdf" to be saved in this subfolder: /S/Sarah John/". All these folders allready exists.

 

To accomplish this, i have tried to parse the filename for each attachment in the mail using the  Substring() expression. This is where it fails, as i cannot get MSFlow to give me the attachment names as a type string i can work with, the "Attachment Name" is an object.

 

As seen here, i want to be able to use RegEx's to be able to tell flow, where to put each file, in the folder path.

 

Anyknow know if this is at all possible ?

 

flow.png

Categories:
  • Verified answer
    v-xida-msft Profile Picture
    Microsoft Employee on at

    Hi @JesperTorp,

     

    I have made a test on my side and please take a try with the following workaround:

    • Add a "When a new email arrives" trigger, Has Attachment field and Include Attachments field both set to Yes.
    • Add a "Apply to each" action, input parameter set to Attachments dynamic content of the trigger.
    • Within "Apply to each" action, add a "Create file" action, specify Site Address and List Name. Folder Path field set to following formula:
    /Reporting/substring(...)​/split(...)

    The substring(...) expression within above formula read as below:

    substring(split(item()?['Name'],'.')[0],0,1)

    The split(...) expression within above formula read as below:

    split(item()?['Name'],'.')[0]

    The File Name field set to following formula:

    concat(triggerBody()?['DateTimeReceived'],'.',split(item()?['Name'],'.')[1])

    The File Content field set to Content dynamic content of the trigger.

     

    Image reference:18.JPG

    The flow works successfully as below:19.JPG

     

    20.JPG

     

    21.JPG

     

     

    Best regards,

    Kris

  • JesperTorp Profile Picture
    5 on at

    Yes, Yes, YES...that was E X A C T L Y what i needed, and it worked like a charm. Thx 🙂

  • NishantAgr Profile Picture
    5 on at

     

     

    @v-xida-msft - Can you please help me out with steps. Please have a look at my scenario:

    Suppose file name is IN_2019_02_07_Invoice.pdf

    • Let’s have sample librarie in the SharePoint site – Invoice
    • Once the file is received via the email, let’s move the files into heirarical folders, Invoice->IN->2019->02->07 these folders are based on Country Code/Current Year/Month/Date.. County code (IN, PO, BU, DE...) in File Name.
    • Also, moving files into folders based on year ->  month will be ‘nice to have’ or even date wise within these libraries

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
Mohsin Ali Profile Picture

Mohsin Ali 424

#2
11manish Profile Picture

11manish 328 Super User 2026 Season 2

#3
M Bilal Khan Profile Picture

M Bilal Khan 274

Last 30 days Overall leaderboard