How to Copy and Rename File in Power Automate?

Have you ever faced a situation where you must copy a file and automatically give it a new name? One of my team members recently asked, “Can we use Power Automate to copy a file and rename it on the go?” The answer is yes! Power Automate makes this task super easy and efficient. Whether you’re managing files in SharePoint, OneDrive, or another storage service, automating, we copy and rename it.

In this tutorial, I will tell you how to copy and rename a file in the SharePoint library if it already exists using Power Automate. Additionally, we will discuss how to copy and rename multiple files in Power Automate.

Copy and Rename a File in SharePoint if it Already Exists using Power Automate

Suppose you want to copy files from one SharePoint document library, Source Documents, to another, Approved Documents. If a file with the same name already exists in the Approved Documents, the flow should automatically rename the file.

Copy and Rename a File in SharePoint if it Already Exists in Power Automate

Follow the steps below to achieve this:

1. Create an automated cloud flow. Give the flow name and select the trigger When a file is created (properties only).  Also, provide the Site Address and Library Name.

Power Automate Copy and Rename a File in SharePoint if it Already Exists

2. Then Add the Copy file action inside the true section and provide the below parameters:

  • Current Site Address: The SharePoint site address where the file you want to copy is located.
  • File to Copy: provide the identifier from dynamic content when creating a file.
  • Destination Site Address: The SharePoint site to which you want to copy the file.
  • Destination Folder: Select the destination SharePoint library.
  • If another file is already there: Selcte Replace, Copy with a new name.
Copy and Rename a File in SharePoint if it Already Exists using Power Automate

Now, click Save and run the flow manually. Once the flow runs, add the same file that is present in the Approved Documents document library.

Copy and Rename a File in SharePoint if it Already Exists Power Automate

After the flow successfully goes to the Approved Documents Document library, you can see the file successfully copied with a different name.

How to Copy and Rename a File in SharePoint if it Already Exists in Power Automate

Copy and Rename Files in Power Automate

Suppose you are managing a document library in SharePoint called Monthly Reports. Every month, team members upload reports to this library with a standard naming convention, such as SalesReport_January2024.docx. To keep the library organized and maintain a backup, you want to create a Power Automate flow that:

  • Copies of each uploaded report to an Archive folder in the same document library.
  • Rename the copied file to include the current month and year, then the file name.
Copy and Rename File in Power Automate

Now follow the below steps:

1. In the Power Automate, click the Instant Cloud flow, enter the Flow name, and choose the trigger flow (i.e., manually trigger a flow).

Copy and Rename Files in Power Automate

2. Add Get files (properties only) and provide the below parameters to retrieve all files:

  • Site Address: Select the SharePoint site address, which, in my case, is PowerAutomateTutorial.
  • Library Name: Select the SharePoint library name, which, in my case, is Monthly Reports.
  • Filter Query: Provide the below filter query.
ContentType eq 'Document'
Copy and Rename Files using Power Automate

3. Add Get file content and provide the below parameters:

  • Site Address: Select the SharePoint site address, which, in my case, is PowerAutomateTutorial.
  • File Identifier: Provide an Identifier from the dynamic content of Get files (properties only).

It will automatically add a For each action.

Copy Files and Rename  in Power Automate

4. Inside the for each add Create file action and provide below parameters:

  • Site Address: Select the SharePoint site address, which, in my case, is PowerAutomateTutorial.
  • Library Name: Select the SharePoint Folder name.
  • File Name: Provide below data:
@{formatDateTime(utcNow(),'MMMM yyyy')}_@{item()?['{FilenameWithExtension}']}
Power Automate Copy Files and Rename

Now, click save and run the flow manually after it runs successfully. Then, go to the SharePoint library folder, and you will see that the files have been copied.

How to Copy and Rename Files in Power Automate

You can apply the same approach in OneDrive to copy and rename files in Power Automate. The only difference is that you must use the ‘Create file’ action from the OneDrive connector instead of the SharePoint connector.

Conclusion

In this tutorial, I covered two scenarios for copying and renaming files in SharePoint using Power Automate. In the first scenario, I show how to copy a file from one document library to another and automatically rename it if a file with the same name already exists in the destination library.

The second scenario explains how to copy files from a SharePoint library to an Archive folder within the same library and rename them to include the current month and year for better organization.

You may also like:

>
Download User registration canvas app

DOWNLOAD USER REGISTRATION POWER APPS CANVAS APP

Download a fully functional Power Apps Canvas App (with Power Automate): User Registration App

Power Platform Tutorial

FREE Power Platform Tutorial PDF

Download 120 Page FREE PDF on Microsoft Power Platform Tutorial. Learn Now…