Power Automate Rename File

In this Power automate tutorial, we will discuss the Power automate rename file. And also we will discuss the below points:

  • Power automate rename file with date
  • Power automate rename file in SharePoint
  • Rename all files in a SharePoint document library using Power Automate
  • Power automate rename file extension
  • Power automate rename file OneDrive
  • How do you rename all the files in the document library, instead of For a selected file?

Let us see, how to rename file using Power Automate or Microsoft Flow.

Power Automate rename file with date

Here we will see how to rename a file with the date in Microsoft Flow or Power Automate.

In the SharePoint document library, I have an excel file called Balance.xlsx. Now I want to rename the file to BalanceSheet with the current date appended in it by using Microsoft Flow.

flow rename a file in SharePoint
flow rename a file in SharePoint

Steps to rename a File with date in Microsoft Flow

Let us now step by step create a flow that will rename the file.

Step 1: Create a flow in Power Automate

Now we will create a flow to rename a file with the current date.

  • Login to Power Automate, then click on create and select Instant cloud flow.
flow rename a file in SharePoint
flow rename a file in SharePoint
  • Now Provide the flow name and select the Mnually trigger Flow.
power automate rename excel file
power automate rename excel file

Step 2: Get File Content from the SharePoint

In this step, we will Get file content which file name you want to change in SharePoint.

So, click on the Next Step, then select Get File content- SharePoint action. Then provide the site address and File identifier.

power automate rename file with date
power automate rename file with date

Step 3: Rename a file with the date

To rename a file we will create a file in the SharePoint document library. So for this click on the next step and then select Create a file-SharePoint action.

After that provide the site address and Folder path where you want to save the file. Then provide the file name as the Balance sheet and to add date write the below expression:

formatDateTime(utcNow(),'yyyy-MM-dd')

Then add the extension. Next, add the file content from the dynamic content.

power automate rename file with date
power automate rename file with date

Step 4: Run the Flow

Now click on save and run the flow manually, once flow ran successfully.

How to rename file using Microsoft Flow
How to rename file using Microsoft Flow

After that, we can see the SharePoint document library where we store the file is renamed.

power automate rename file
power automate rename file

In this example, we saw how to rename a file using Power Automate. In this case, particularly, we appended the current date with the file name.

Check out, Power Automate Get Data from Excel on SharePoint

Power automate rename file in SharePoint using Http Request

Here we will see how to rename a file in SharPoint using Http request.

In the SharePoint Document library, I have an excel file called ‘RenamedDocument’ which we want to rename to Product Review, without losing the version History and audacity on the original file, and this can happen via Http request.

power automate rename excel file
power automate rename excel file

Steps to rename a file in SharePoint using Power Automate

See also  Power BI Filter vs Slicer

Step 1: Create a Flow in Power Automate

To create a Flow, Login to Power Automate, then click on Create and select instant cloud flow.

how to rename a file in SharPoint using Http request
how to rename a file in SharePoint using Http request

Now provide the Flow name and select the trigger i.e. ‘For a selected File‘- SharePoint.

power automate rename excel file in SharePoint
power automate rename excel file in SharePoint

Step 2: For a selected File in SharePoint

In this step, provide the SharePoint site address and Library name of the file which you want to rename.

power automate rename excel file in SharePoint
power automate rename excel file in SharePoint

Step 3: Get File Properties

In this step, we will get the file properties of the file that we want to rename.

So for this click on the Next step, then select Get File Properties– SharePoint. And then provide the SharePoint site address, library name, and Id of the file.

power automate rename file in SharePoint
power automate rename file in SharePoint

Step 4: Rename the File in SharePoint

To rename the file we will send the Http request to SharePoint.

So click on the Next step, select ‘Send an Http request in SharePoint‘ action.

Then Provide the site address and in the method select the Post from the list. Next, we will provide the Uri, we can get the URI by following the below steps:

  • Copy the site url
  • Then open the new tab in browser and paste the url.
  • Next remove all other part after the site name ‘https://tsinfotechnologies.sharepoint.com/sites/EnjoySharePoint’
  • Now we will add the api like below:
https://tsinfotechnologies.sharepoint.com/sites/EnjoySharePoint/_api/lists/GetByTitle('Documents')/Items(7)

So in this replace the ‘Documents’ with your document library and 7 with your item id number. Then click enter, you will come across XML like below.

power automate rename file
power automate rename file

Next copy the URL from the _api and then paste it in the Uri section, after that change the 7 with the id of the file from dynamic content.

Next in the headers, part add the header and value like below

HeaderValue
content-typeapplication/json;odata:verbose
IF-MATCH*
X-HTTP-METHODPATCH
power automate rename excel file in SharePoint

Then in Body part add the json, in type we can get it from XML which we have in previous steps.

So go to that XML and then select ctrl+F, in the finder box search ‘sp data’ so you will come across below text

power automate rename excel file in SharePoint
power automate rename excel file in SharePoint

At last in FileLeafRef add the name which you want to rename.

Rename file in SharePoint using Microsoft flow
Rename file in SharePoint using Microsoft flow

Once your flow is ready we will test the flow manually.

Step 5: Run the Flow

When you save the flow and you want to run the flow in Microsoft Flow, you will come through this type of warning.

power automate rename file in SharePoint
power automate rename file in SharePoint

To run the flow go to the SharePoint Document Library, where you have stored your file.

Then select the file, click on the More icon -> Power Automate -> you can see your flow name.

power automate rename excel file in SharePoint
power automate rename excel file in SharePoint

Then your flow will run and you can see the file get renamed.

power automate rename excel file in SharePoint
power automate rename excel file in SharePoint

And also you can check the flow in the Microsoft flow:

power automate rename excel file
power automate rename excel file

Also read, Power Automate send an email with an attachment from SharePoint

See also  PowerApps nested gallery control example

Power automate rename file extension

Here we will see how to rename the file extension using power automate.

So I have an excel file in the SharePoint library, so we will change the file to pdf using Power automate.

In Power automate, select the manually triggered flow option, and then click on the next step.

power automate rename file extension
power automate rename file extension

Select the Get File content action, provide the site address and file identifier of the file.

flow rename file in SharePoint
flow rename file in SharePoint

Next click on the Next step, then select create a file action. Then provide the site address, folder path, in filename add the extension to pdf and in file content add the content from the dynamic content.

power automate rename file extension
power automate rename file extension

Once the flow is ready, save and run the flow manually. You can see the flow run successfully.

power automate rename files in folder
power automate rename files in folder

After that, we can check the file extension is renamed or not, so for this go to the document library.

power automate rename file extension
power automate rename file extension

Also, read, Power Automate update SharePoint list item

Power automate rename file OneDrive

Here we will see how to rename a file in OneDrive using Power automate.

I have a weekly report which I upload the report in one drive every week. So I want the file gets renamed with the current date. if the date is 2021-06-12, then the file gets renamed to weekly report 2021-06-12.

Steps to rename file in OneDrive using Microsoft Flow

Step 1: Create a Flow in Power automate

To create a flow click on Create and then select Automated cloud flow.

Microsoft flow rename file in OneDrive
Microsoft flow rename file in OneDrive

Next, provide the flow name and select the ‘When a file is created‘-onedrive business. Click on Create.

Microsoft flow rename file in OneDrive
Microsoft flow rename file in OneDrive

Step 2: When a file is created in OneDrive

In this step provide the folder name, where you want to create a file.

Microsoft flow rename file in OneDrive
Microsoft flow rename file in OneDrive

Step 3: Rename a file using Path

To rename a file click on the Next step, and then select the ‘Move or rename a file using path’ action.

Then provide the file path from the dynamic content, then in Destination file path add the path with rename file with current date expression and overwrite choose yes from dropdown.

formatDateTime(utcNow(),'yyyy-mm-dd')
flow rename file in OneDrive
flow rename file in OneDrive

Once your flow is ready click on save and run the flow manually.

Step 4: Run the Flow

To run the flow click on save and upload a file to the OneDrive, once the flow will trigger it will rename the uploaded file.

power automate rename file OneDrive
power automate rename file OneDrive

Once the Flow ran successfully check the OneDrive that the file gets renamed.

power automate rename file OneDrive
power automate rename file OneDrive

This is an example of a Power Automate rename file in OneDrive.

How to rename all files in a SharePoint document library using Power Automate

Here we will see how to rename all files in the SharePoint Document library, instead of For a selected File.

I have a SharePoint Document Library called Contract, so here we will all the files present in the Contract library without losing the file’s properties, audacity, and version history of the original file, and this can happen using an HTTP request.

Power automate rename all files
Power automate rename all files

Steps to rename all files in the SharePoint Document Library using Power Automate.

See also  How to Get Gallery Item By ID in Power Apps

Step 1: Create a Flow in Power Automate

To create a flow, log in to Power Automate, then click on Create, select Instant cloud Flow.

How do you rename all the files in the document library
How do you rename all the files in the document library

Now provide the flow name and select the trigger as ‘Manually triggered Flow‘.

Power automate rename all files
Power automate rename all files

Step 2: Get all files with properties

To rename all files, so click on the Next step and select the Get Files (Properties only) action. Then provide the site address and Library name and Top count as 100.

Power automate rename all files in document library
Power automate rename all files in document library

Step 3: Rename all files in the SharePoint library

Now we will see how to rename all files in the SharePoint library using HTTP requests. So, click on the Next step and select ‘Send an HTTP request to SharePoint‘ action, then provide the site address, and in the Method field select the Post from the option. Next, we will provide the Uri, so for this follow the below step:

  • Copy the site URL
  • Then paste in new tab in the browser
  • Next remove all other part after the SharePoint site name ‘https://tsinfotechnologies.sharepoint.com/sites/EnjoySharePoint’
  • Now we will add api like below:
https://tsinfotechnologies.sharepoint.com/sites/EnjoySharePoint/_api/lists/GetByTitle('Contract')/Items()

And in ‘Items()’, inside bracket add ID from the dynamic content.

Then in the header section, add the header and value like below.

HeaderValue
content-typeapplication/json;odata:verbose
IF-MATCH*
X-HTTP-METHODPATCH
Power automate rename all files

Now in the body part add the JSON code like below, in type, we can get it from XML which we had in the previous step i.e Uri, in title add sample, and in File ref provide the renamed file.

{'__metadata':
{'type': 'SP.Data.Shared_x0020_DocumentsItem'},
'Title':'Sample',
'FileLeafRef':'Sample.docx'}

To get the type in the above JSON, go to the XML code, then select Ctrl+F, and in the Finder box search SP. Data, so you will come across the below image

MS flow rename all files in document library
MS flow rename all files in the document library

After providing all the values you can now send an HTTP request to rename all files and it will automatically add the Apply to each action.

Microsoft flow rename all files in- document library
Microsoft flow rename all files in a document library

Once your flow is ready you can move forward to test the flow.

Step 4: Run the Flow

Now click on Save and run the flow manually, and you can see all the files in the document library are renamed.

How Microsoft flow rename all files in a document library
How Microsoft flow rename all files in a document library

This is an example of Power Automate renaming all files in the SharePoint library.

You may also like the following Power Automate tutorials:

In this Power Automate tutorial, we discuss the power automate rename file. And also we discuss the below points:

  • Power automate rename file with date
  • Power automate rename file in SharePoint
  • Power automate rename file OneDrive
  • Power automate rename file extension
  • How to rename all the files in a SharePoint document library using Power Automate
  • How do you “Go to the XML Code”? Do I need to be in the sharepoint library? The home page of the site? Where do I click to display XML code? I am a novice and have no idea how to do this step.

  • I followed your “Power automate rename file in SharePoint using Http Request” guide. Everything went fine, except the “Send an HTTP request to SharePoint” step in the flow runs and runs, and eventually returns a “BadGateway” error. I’ve confirmed that the account authorized within the SharePoint library is the account I’m running the flow with. How do I troubleshoot this?

  • Rename file extension created a new file and it did not replace it.
    Can anyone help with this.
    Is there a way to rename the file extension without creating a new file.
    I also did not get the option: Create file-Rename a file extension, i get create file only.
    In the last step, i was not able to choose body as the identifier as well.

  • >