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

Community site session details

Session Id : bdmzy+C3ow8guyQ6snmaCR
Power Automate - Building Flows
Answered

Rename file step adding [ _ characters

Like (0) ShareShare
ReportReport
Posted on 23 Nov 2022 22:47:45 by

Hi team, I have created a flow to grab an attachment from an email, rename it to add the date on the end, and save to a SharePoint folder. The flow is working, but the file name ends up with additional characters either side of the original attachment name, i.e. [_Agent State Details Report_]_20221122.csv

 

While the additional characters aren't inhibiting any other processes, I'd like to understand why it's happening.

 

The rename steps and expressions are as follows:
1. Initialize variable: Name - Rename Attachment, Type - String
2. Get Attachment Name: first(split(variables('RenameAttachment'), '.'))
3. Get Attachment Extension: last(split(variables('RenameAttachment'), '.'))
4. New Attachment Name: concat(outputs('Get_Attachment_Name'), '_', formatDateTime(utcNow(), 'yyyyMMdd'), '.', outputs('Get_Attachment_Extension'))

 

 

I have the same question (0)
  • SudeepGhatakNZ Profile Picture
    14,381 Most Valuable Professional on 24 Nov 2022 at 01:25:56
    Re: Rename file step adding [ _ characters

    Have you investigated the flow output?

     

  • Community Power Platform Member Profile Picture
    on 24 Nov 2022 at 02:00:25
    Re: Rename file step adding [ _ characters

    Could you please elaborate, is the output not the renamed file?

  • Ajinder31 Profile Picture
    530 on 24 Nov 2022 at 05:33:06
    Re: Rename file step adding [ _ characters

    Hi @Anonymous , I believe @SudeepGhatakNZ meant to confirm if we checked the output of the step 2. Get Attachment Name: first(split(variables('RenameAttachment'), '.')) in the flow. We suspect [ _ are part of the variable RenameAttachment in flow already and are not added by the flow. Please check the output of flow and confirm.

  • grantjenkins Profile Picture
    11,059 Moderator on 24 Nov 2022 at 08:26:50
    Re: Rename file step adding [ _ characters

    It's hard to tell without knowing how you initially set your RenameAttachment variable.

     

    One thing I noticed is that to get the name you split on period then take the first item. If you have one or more periods in the actual file name, then this will only return the name up to the first period - not necessarily the full name up to the extension.

     

    Below is how I would get the reformatted name.

    grantjenkins_7-1669278378289.png

     

    attachmentName is set to the first Attachment Name using the following expression:

    first(triggerOutputs()?['body/attachments'])?['name']

    grantjenkins_5-1669278086405.png

     

    Then, get the last index of "." which should be the period that splits the name and the extension.

    lastIndexOf(variables('attachmentName'), '.')

    grantjenkins_4-1669278058503.png

     

    And finally, concatenate the name and date using the following expression.

    concat(slice(variables('attachmentName'), 0, outputs('Index')), '_', formatDateTime(utcNow(), 'yyyyMMdd'), slice(variables('attachmentName'), outputs('Index')))

    grantjenkins_6-1669278156247.png

     

  • Community Power Platform Member Profile Picture
    on 24 Nov 2022 at 21:30:50
    Re: Rename file step adding [ _ characters

    Hi @grantjenkins  thanks for providing some extra information. My steps look different to yours - looks like I have an extra "Apply to each" step which might be what's catching me up?

    vww_2-1669325400135.png

     

    Here's the Initialize variable and Apply to each steps expanded, am I overcomplicating things?

    vww_3-1669325413485.png

     

     

     

     

  • Verified answer
    grantjenkins Profile Picture
    11,059 Moderator on 25 Nov 2022 at 03:49:55
    Re: Rename file step adding [ _ characters

    Your loop is ok - if you only have a single attachment then it would only loop once and set the Attachment Name. I've just retrieved the first attachment by wrapping it in a first expression which avoids the loop.

     

    I tried with your exact expressions, and it comes out fine for me (including the loop) so no idea where those brackets are coming from.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Chiara Carbone – Community Spotlight

We are honored to recognize Chiara Carbone as our Community Spotlight for November…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 655 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 371 Moderator

#3
chiaraalina Profile Picture

chiaraalina 276

Last 30 days Overall leaderboard
Loading complete