How To Add Date Time Tick To File Name Before Upload In Document Library Using Power Automate

Introduction

In this blog, we will see how to append a date-time tick in the file name using Power Automate.

Scenario

We have a Power App list form. Now we need to store uploaded list item attachments in the document library. So we created Power Automate to get attachments from list item and upload it to the document library. Now the user may upload files with the same name, and it will replace the files with duplicate names. To prevent this, we rename the file by adding a date-time tick in the file name and then uploading it to the document library.

Implementation

Our trigger in Power Automate is PowerApps (V2), and we are passing file content from Power App to Power Automate as shown below screenshot:

How To Add Date Time Tick To File Name Before Upload In Document Library Using Power Automate

Note. Follow the below steps to add the date time tick in the file name.

Step 1

Initialize the below variables.

How To Add Date Time Tick To File Name Before Upload In Document Library Using Power Automate

Note. After initializing variables, you can add other actions if required.

Step 2

Now, we will set the value to the variable. So first, set the below expression in value for the FileNameOnly variable.

substring(triggerBody()['file']['name'],0,lastIndexOf(triggerBody()['file']['name'],'.')) 

How To Add Date Time Tick To File Name Before Upload In Document Library Using Power Automate

Step 3

Now, set the below expression in value for the FileExtensionOnly variable.

 last(split(triggerBody()['file']['name'],'.')) 

How To Add Date Time Tick To File Name Before Upload In Document Library Using Power Automate

Step 4

Now, set the below expression in value for the CurrentDateTime variable.

formatDateTime(utcNow(),'ddmmyyyyhhmmss') 

How To Add Date Time Tick To File Name Before Upload In Document Library Using Power Automate

Step 5

Now, set the below expression in value for the NewFileName variable.

concat(variables('FileNameOnly'),'_',variables('CurrentDateTime'),'.',variables('FileExtensionOnly'))

How To Add Date Time Tick To File Name Before Upload In Document Library Using Power Automate

Step 6

When we use Create File action to upload a document in the document library, use the NewFileName variable for File Name.

How To Add Date Time Tick To File Name Before Upload In Document Library Using Power Automate

So, this is how we can append the date time tick in the file name using Power Automate.

Hope this article will be helpful for you.


Similar Articles