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/replace a file ...
Power Automate
Answered

Rename/replace a file in Sharepoint with HTTP request

(0) ShareShare
ReportReport
Posted on by 20

Hi All,

 

I started this journey thinking such a simple task would have a simple implementation.  The ideal state is:

  1. User: places a new excel file into Sharepoint folder (LoginReport-MMDD-MMDD.xlsx)
  2. Flow: copy new file into archive folder. 
  3. Flow: rename new file (from user) to standard name (i.e. LoginReport-MMDD-MMDD.xlsx rename to NewCitrixDataLoad.xlsx)

Step 3 is where I am having major issues.  There is already a file in the folder with the name NewCitrixDataLoad.  I originally thought Power Automate would just overwrite the old file with the new one, but it errors out with 'File already exists'.  Then I tried making a delete step to delete the file before renaming, but that didn't seem to work either.  After countless hours of research and failures, I am hoping for some assistance.

 

For some reason I can make each of the individual pieces work, but it's when they are in a single flow that something breaks.

My best attempt appears as:

SensingFailure_0-1664912153467.png

 

Any help is greatly appreciated!

Categories:
I have the same question (0)
  • Ellis Karim Profile Picture
    12,014 Super User 2026 Season 1 on at

    Hi @SensingFailure ,

     

    Try:

    The flow could resemble the following:

    Snag_c65e7c6.png

     

    The demo flow uses When a file is created (properties only) trigger:

    Snag_c670a2e.png

    Snag_c678818.png

    The Send an HTTP request to SharePoint request used the method POST:

    Snag_c680e9e.png

    Snag_c686885.png

     

    _api/web/lists/GetbyTitle('Documents')/items(@{triggerOutputs()?['body/ID']})/validateUpdateListItem
    
    {
     "formValues": [
     {
     "FieldName": "FileLeafRef",
     "FieldValue": "NewCitrixDataLoad.xlsx"
     }
     ]
    }

    Hope this helps.


    Ellis
    ____________________________________
    If I have answered your question, please mark the post as Solved.
    If you like my response, please give it a Thumbs Up.

  • SensingFailure Profile Picture
    20 on at

    Thank you so much for your response!  On recreating this flow, there are a few issues I am still experiencing.

    1. Copy file - Is copying both the newly uploaded LoginReport file, but also the existing NewCitrixDataLoad file to the archive folder.  The ideal state is for only the newly uploaded file.
    2. HTTP request is still failing with the error "A file with the name /Dashboard Repository/Dashboard Source Files/ClassNet Analysis/CitrixData/NEWMODEL/CitrixDataFiles/NewCitrixDataLoad.xlsx already exists."  I'm not sure why this is still happening.

    I tried inserting a delete step prior to the HTTP request to solve this, but then am met with an error that the NewCitrixDataLoad does not exist.  

     

    Any additional thoughts?

  • Verified answer
    grantjenkins Profile Picture
    11,063 Moderator on at

    If you weren't worried about keeping the actual original file then you could just do the following:

    1. Trigger When a file is created in a folder with two trigger conditions:
      1. Only files that start with LoginReport
      2. Only files that end with .xlsx
    2. Copy the file to the Archive folder setting it to Move with a new name (or overwrite if you want)
    3. Create a file using the original file's content specifying the name NewCitrixDataLoad (should automatically overwrite if file with same name already exists
    4. Delete the original file

     

    Note that adding trigger conditions are much better than having condition logic in the flow as you won't even get a flow run if any of the trigger conditions evaluate to false.

     

    The trigger conditions are below:

     

    @startsWith(string(triggerOutputs()?['headers/x-ms-file-name']),'LoginReport')
    @endsWith(string(triggerOutputs()?['headers/x-ms-file-name']),'.xlsx')

     

     

    grantjenkins_1-1665575672468.png

     

    To add the trigger conditions just click on the ... next to the Trigger and select Settings, then add your conditions.

    grantjenkins_2-1665575943626.png

     

     

    And the flow itself:

    grantjenkins_0-1665575517150.png

     

  • SensingFailure Profile Picture
    20 on at

    Thank you SO MUCH!  This worked fantastically!

  • adinata Profile Picture
    2 on at

    Hi everyone,

    I'm experiencing the same issue

    I'm trying to rename a folder/file. Below are the screenshots:

    This is for rename the folder

    Screenshot 2023-09-01 070035.png

     

    and this is for rename the file

     

    Screenshot 2023-09-01 070255.png

     

    but i got this error:

    The URL 'url' is invalid.  It may refer to a nonexistent file or folder, or refer to a valid file or folder that is not in the current Web.

     

    I hope someone can help to solve this issue. many thanks!

     

    cheers

    Adi

     

     

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 March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Haque Profile Picture

Haque 639

#2
Valantis Profile Picture

Valantis 392

#3
11manish Profile Picture

11manish 350

Last 30 days Overall leaderboard