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 / Create a copy of the m...
Power Automate
Unanswered

Create a copy of the most recent file in a SharePoint library folder to the same folder

(0) ShareShare
ReportReport
Posted on by 31
Hello, 
I need help creating a Power Automate flow that checks a SharePoint folder for the most recent file (in my case excel file) and then create a copy of the file in the same folder but with a new name appended with the current month and year.
Thank you.
Categories:
I have the same question (0)
  • Rohit Jagadale Profile Picture
    16 on at

    Thanks for sharing your scenario. To make sure I understand correctly, could you please clarify a few details:


    1. When the file is first created, do you want to immediately create a copy with the new name (appending the current month and year)?

    2. Will the first file be uploaded manually by a user, or is it created automatically by some other process?

    3. Should this flow run every time a new file is added, or only for a specific file or type of files?

    4. Once I have these details, I can suggest a clean Power Automate approach for copying the latest file with the correct naming logic.



    5.  

     
  • David_MA Profile Picture
    14,689 Super User 2026 Season 1 on at
    You’ll need to be cautious in your approach. As it's currently outlined, there's a real potential for this process to create an infinite loop. When the flow runs and creates a copy of the file, that new file will trigger the flow again, which will lead to repeated runs.
     
    What’s the purpose of creating these copies? Understanding that might help identify a safer and more efficient approach.
     
    Also, keep in mind: every newly created file becomes the “most recent,” so without filtering, the flow will keep picking up its own output.
     
    Is a specific person responsible for creating the original files? If so, you could add a trigger condition to only run the flow when that person creates a file. This can work well as long as that person isn’t you, the owner of the flow, since your actions may bypass the condition depending on how the flow is configured.
  • Kedet Profile Picture
    31 on at
    @Rohit Jagadale and @David_MA for context, the flow is meant to run every month. i.e a scheduled flow. 
    The purpose of creating a copy is because changes will be made to the copied file.
     
    The file is usually uploaded manually in the SP folder by a user every month that's why we need a flow to run monthly and pick the latest file and then rename it with the current month and year.
     
    Before the flow runs the following month, another file would have been manually uploaded to the SP folder.
    Please let me know if this clarifies it or you have more questions.
    Thanks.
  • David_MA Profile Picture
    14,689 Super User 2026 Season 1 on at
    I can get you started, but you will need to clarify what you actually want to do. In your original post you said you wanted to make a copy of the Excel file, but then in your follow up, you said you just want to rename it. Which do you need to do?
     
    If you want this to run as a scheduled flow, do this:
    • Set up the flow with the recurrence trigger and configure it to when you want it to run.
    • Use the get files (properties only action) configured with these settings:
      • Site address: your SharePoint site
      • Library name: your document library
      • Limit entries to folder: choose the folder where the file is supposed to be uploaded to
      • Include nested items: no
      • Filter query: substringof('.xlsx', FileLeafRef)
        • Modify the above if your Excel spreadsheet doesn't end with xlsx.
      • Order by: Created desc
      • Top count: 1
      • The above settings will get the most recent Excel file in the folder.
    • Add a condition and use the length expression to determine if one Excel file was returned.
      • Use this expression on the left side of the condition: length(outputs('Get_files_(properties_only)')?['body/value']) and set it to is equal to 1
    • On the yes side of the condition, and an Apply to each action and set it to the value of the Get files action
    The flow will look like this except instead of a manually triggered flow, you will use a scheduled flow. However, you can initially set it up with the manual trigger to test it, then delete the manual trigger and replace it with recurrence.
     
    Assuming you want to rename the file as stated in your last post, you can follow the directions outlined at Rename a file in SharePoint with a single Power Automate action which is the HTTP request in the apply to each above.
     
  • Kedet Profile Picture
    31 on at
    Thank you @David_MA but I'm struggling with the Uri in the "Send HTTP request to SharePoint" action.
     
    The file is located in a folder inside a document library. i.e Document Library -> Folder -> File
     
    How do I write the Uri? I've tried different things but still not working.
    Thanks.
  • David_MA Profile Picture
    14,689 Super User 2026 Season 1 on at
    The folder path does not matter for the HTTP request to rename the file because you are specifying the ID of the file in the Uri. In the link I provided on how to do this, where it shows the image below, the 'Documents' value in the Uri is the display name of your document library. You would replace 'Documents' with whatever it shows in the title of the document library. This should not include the path. This is a weird bug, but if for some reason the display name of the document library does not begin with a capital letter, be sure to capitalize the first letter in the Uri or it will fail.
     
     
    The Uri should be created as in the post: Uri: _api/web/lists/GetByTitle('<LibraryName>')/items(<DocumentID>)/validateUpdateListItem
     
    You just replace <Library Name> with the name of your document library and replace <DocumentID> with the ID from the Get files (properties only) action.
     
  • Kedet Profile Picture
    31 on at
    It came back with item does not exist error. What I'm I doing wrong?
    Screenshot attached.
    Screenshot 2025-08-15 192349.png
    Screenshot 2025-08-15 192308.png
  • David_MA Profile Picture
    14,689 Super User 2026 Season 1 on at
    Based on what you shared and the error message you got, it is probably one of two things:
    1. Since the flow says the item does not exist, someone deleted the item when you triggered the flow. This seems unlikely to me, but it is possible.
    2. The more likely option is that you do not have the correct display name value of your document library in the HTTP request. Please share a screen shot of the configuration of the Get files action. You can redact the URL of your SharePoint site in the screen shot, but I need to see the document library name in this action.
      1. In the HTTP request, the display name of the document library needs to match in the Uri. The display name of the document library goes after Title in the Uri and is between the quotes. Currently you have, Title('Documents') which matches what I showed and also matches what is in the link I shared. Usually this is the name of the default document library in SharePoint online, but if you are getting files from another document library or someone changed the display name of the document library, then you need to update this in the Uri.
  • Kedet Profile Picture
    31 on at
    Hi @David_MA, the file was not deleted and here is the screenshot of the get files.
    Thanks.
     
    Attachment is recent reply
  • Kedet Profile Picture
    31 on at
    Hi @David_MAthe file was not deleted and here is the screenshot of the get files.
    Thanks.
     
     
    1755790545205blob.jpg

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!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Vish WR Profile Picture

Vish WR 464

#2
Haque Profile Picture

Haque 431

#3
David_MA Profile Picture

David_MA 323 Super User 2026 Season 1

Last 30 days Overall leaderboard