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.
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.
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.
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.
After the flow successfully goes to the Approved Documents Document library, you can see the file successfully copied with a different name.
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.
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).
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'
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.
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}']}
- File Content: Provide the File Content from dynamic content.
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.
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:
- Power Automate Copy Folder
- Power Automate Copy File When a File is Created or Modified in SharePoint
- Copy New Files from Your PC to SharePoint using Power Automate
- Copy List Items To Another List In SharePoint Using Power Automate
- Power Automate vs Nintex: Key Differences for Workflow Automation
I am Bijay a Microsoft MVP (10 times – My MVP Profile) in SharePoint and have more than 17 years of expertise in SharePoint Online Office 365, SharePoint subscription edition, and SharePoint 2019/2016/2013. Currently working in my own venture TSInfo Technologies a SharePoint development, consulting, and training company. I also run the popular SharePoint website EnjoySharePoint.com