Skip to main content

Notifications

Power Automate - General Discussion
Answered

Change the file name of attachment

(0) ShareShare
ReportReport
Posted on by

Hi everyone,

When creating the auto save attachment rule in Outlook mail, I also want to change the file name of the attachment as: "YYYY.MM.DD.pdf" or "YYYY.MM.DD.xlsx" , Could anyone help me to change the files name please?

 

 

Anna_Phuong_0-1679906798765.png

 

  • Chriddle Profile Picture
    Chriddle 7,276 on at
    Re: Change the file name of attachment

    Ok, here an example:

    Chriddle_1-1682062064421.png

     

    AttachmentNoWithFileExtension:

    last(split(items('Apply_to_each_Attachment')['name'], '_'))

     

    AttachmentNo:

    first(split(last(split(items('Apply_to_each_Attachment')['name'], '_')),'.'))

     

    Output:

    Chriddle_2-1682062274242.png

     

  • Re: Change the file name of attachment

    Hi Chriddle,

    I mean the attachment name is not fixed, for example: its name can be Bang_so_1_CN_270323.pdf, Bang_so_1_CN_280323.pdf,... This name will change everyday when I received the email. So I don't know how to put the attachment name in the split function of your formula: last(split('Bang_so_1_CN_270323.pdf', '.')[0]).

  • Chriddle Profile Picture
    Chriddle 7,276 on at
    Re: Change the file name of attachment

    You are talking about the last character before the dot ("Bang_so_1_CN_270323.pdf")?

    Here are some ways to get it (from sane to hilarious) 😉

    last(split('Bang_so_1_CN_270323.pdf', '.')[0])
    
    reverse(chunk('Bang_so_1_CN_270323.pdf', 1))[4]
    
    take(skip(reverse(chunk('Bang_so_1_CN_270323.pdf', 1)), 4), 1)
    
    substring('Bang_so_1_CN_270323.pdf', sub(length('Bang_so_1_CN_270323.pdf'), 5), 1)
    
    chunk('Bang_so_1_CN_270323.pdf', 1)[sub(lastIndexOf('Bang_so_1_CN_270323.pdf', '.'), 1)]
    
    substring('Bang_so_1_CN_270323.pdf', sub(lastIndexOf('Bang_so_1_CN_270323.pdf', '.'), 1), 1)

     

  • Re: Change the file name of attachment

    Hi Chriddle,

    Because the file attachment name is not fixed as "Bang_so_1_CN_270323.pdf", so can you suggest me how to a get the last character of the attachment name?

  • Chriddle Profile Picture
    Chriddle 7,276 on at
    Re: Change the file name of attachment

    Just checked, the length in substring is optional and not needed here:

     

    substring(
    	'Bang_so_1_CN_270323.pdf',
    	sub(
    		length('Bang_so_1_CN_270323.pdf'),
    		10
    	)
    )

     

  • Chriddle Profile Picture
    Chriddle 7,276 on at
    Re: Change the file name of attachment

    If the fields in the name are divided by an underscore, the easiest approach would be this:

    last(split('Bang_so_1_CN_270323.pdf', '_'))

     

    If not, and you always need the last ten characters, you can use this:

    substring(
    	'Bang_so_1_CN_270323.pdf',
    	sub(
    		length('Bang_so_1_CN_270323.pdf'),
    		10
    	),
    	10
    )

    or a bit safer (no need to repeat your value and it works with too short names as well)

    join(
    	reverse(
    		take(
    			reverse(chunk('Bang_so_1_CN_270323.pdf', 1)),
    			10
    		)
    	),
    	''
    )

     

  • Re: Change the file name of attachment

    I mean the attachment name is "Bang_so_1_CN_270323.pdf" and I want to set the name of file like the red box below. Could you show me how to set rule to save the name like this?

     

    Anna_Phuong_0-1680076506590.png

     

  • Chriddle Profile Picture
    Chriddle 7,276 on at
    Re: Change the file name of attachment

    Your are talking about the file extension?

    You can get it with

    last(split(the_file_name, '.'))

     

  • Re: Change the file name of attachment

    Could you please help me how to use 6-end letter of the file name to set the name of the attachment?

    Thank you in advance !

  • Verified answer
    Chriddle Profile Picture
    Chriddle 7,276 on at
    Re: Change the file name of attachment

    Use this expression as filename:

    concat(utcNow('yyyy.MM.dd'), '.pdf')

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

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,304

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,703

Leaderboard