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 / rename file attachment...
Power Automate
Answered

rename file attachment with timestamp

(0) ShareShare
ReportReport
Posted on by 2,249
 
I need to check if email file attachment name already exists in document library then i need to append time stamp to the file and then create new file.
 
 
Categories:
I have the same question (0)
  • CU08111613-0 Profile Picture
    14 on at
    Start your flow with a trigger that detects a new email. Use the trigger "When a new email arrives" to initiate the flow.

    Use the "Get attachments" action to retrieve the attachments from the email.

    Use an "Apply to Each" loop to iterate through all the attachments.

    Within the Apply to Each loop, use the "Get files (properties only)"

    Set a Filter Query to check for files with the same name ( FileLeafRef eq 'AttachmentName')
    Replace 'AttachmentName' with the dynamic content that represents the attachment name

    Add a Condition after the "Get files (properties only)" action
    Check if the length of the output from "Get files (properties only)" is greater than zero   length(body('Get_files_(properties_only)?')['value'])     

    If True (file exists), proceed to the next step to rename the file

    If the file already exists, create a Compose action to generate the new file name with a timestamp
    concat(triggerOutputs()?['headers']['x-ms-file-name-encoded'], '_', utcNow(), '.ext')
    Replace .ext with the appropriate file extension

     
  • Suggested answer
    Nived_Nambiar Profile Picture
    18,136 Super User 2026 Season 1 on at
    Hi,
     
    You can modify the code like below
     
    After validating condition whether attachment name does not contain png, then in yes branch, use get files to check whether file name with same as attachment name exists within given folder
     
     
     
    Use get attachment to get attachment content like below
     
     
    Now use a condition action to check whether there is output from get files action, if yes - it means file exists , else not
     
     
    Expression: 
    length(outputs('Get_files_(properties_only)')?['body/value'])
     
    if the above condition is true- it means no such file exists so flow can proceed to create file same as attachment name 
     
    Else if condition is false- it will create the file with timestamp appended in file name like below
     
    Expression used: 
    concat(split(outputs('Get_Attachment_(V2)')?['body/name'],'.')?[0],formatDateTime(utcNow(),'ddMMyyyhhmmss'),'.',split(outputs('Get_Attachment_(V2)')?['body/name'],'.')?[1])
     
     
    Hope it helps !
     
    Mark it as solution if it resolves your query !
     
    Thanks & Regards,
    Nived N
  • Veblitz Profile Picture
    2,249 on at
     
    Files are getting stored outside the folder for the first time and for the same file its appending timestamp but its getting stored inside the folder.
     
    Everytime for new file its not copied into folder path, kindly help
     
     

     
     
     
     
     
  • Verified answer
    Nived_Nambiar Profile Picture
    18,136 Super User 2026 Season 1 on at
    Hi,
     
    you need to specify the folder path where file need to be created/saved 
     
     
     
    That would helps !
     
    Thanks & Regards,
    Nived N

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Automate

#1
David_MA Profile Picture

David_MA 77 Super User 2026 Season 1

#2
Haque Profile Picture

Haque 68

#3
Expiscornovus Profile Picture

Expiscornovus 56 Most Valuable Professional

Last 30 days Overall leaderboard