cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MccorryIT
Level: Powered On

Rename file in ODFB when the file is modified

Hi,

 

I want to setup a flow to rename the modified file in ODFB with timestamp. Please advise.

10 REPLIES 10
Community Support Team
Community Support Team

Re: Rename file in ODFB when the file is modified

Hi @MccorryIT,

 

Do you mean the time when the file was modified as the file name?

You could use utcNow() to get the current time, then use replace() function to remove the previous file name, leave the extension, and use the concat() function to add the current time.

Could you share a screenshot of your Flow configuration?

Different triggers may cause different expressions to be written. I use When a file is modified(properties only)(Preview) as an example here. Perhaps you could use it for reference:

Expression:

concat(replace(triggerBody()?['Path'],triggerBody()?['DisplayName'],''),utcNow(),'.',last(split(triggerBody()?['DisplayName'],'.')))

33.PNG

Please take a try and feel free let me know if you have any question.

 

Best Regards,

Barry

Community Support Team _ Barry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
MccorryIT
Level: Powered On

Re: Rename file in ODFB when the file is modified

Hi Barry,

 

i have followed the instruction given but there was some error.

 

  1. It renamed the folderBU7.PNG
  2. It renamed the excel file even its not editexcel.PNG
  3. Flow historyflow history.PNG
  4. My flowmyflow.PNG

Community Support Team
Community Support Team

Re: Rename file in ODFB when the file is modified

Hi @MccorryIT,

 

The image you uploaded seems to be out of order. Can you upload it again?

 

Regards,

Barry

Community Support Team _ Barry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
MccorryIT
Level: Powered On

Re: Rename file in ODFB when the file is modified

Yes i have edited the post.

Community Support Team
Community Support Team

Re: Rename file in ODFB when the file is modified

Hi @MccorryIT,

 

Do you have subfolders when configuring the trigger? Please select Yes.

Alternatively you can add a condition before performing rename action.

Perform the following operations only if the changes are not in the folder.

40.PNG

I did a lot of testing on my side and didn't encounter the problem you said.

It's worth noting that if you change the file, it will inevitably generate a loop, because the nature of your trigger is triggered when there is a file change, and your rename operation is to change the file.

 

Best Regards,

Barry

Community Support Team _ Barry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
MccorryIT
Level: Powered On

Re: Rename file in ODFB when the file is modified

Yes i agree with you that it will generate a loop when the filename renamed. Any idea to deal with this?

Community Support Team
Community Support Team

Re: Rename file in ODFB when the file is modified

Hi @MccorryIT,

 

You could use a series of operations such as Get file content-Create file to rename file.

You could freely rename files when you configure Create file action.

Then delete the previous file.

Be sure to check if you have other Flows that have similar operations on the same folder, which may affect each other.

Expression reference:

replace(triggerBody()?['Path'],triggerBody()?['DisplayName'],'')
concat(utcNow(),'.',last(split(triggerBody()?['DisplayName'],'.')))

42.PNG

Please try again.

 

Best Regards,

Barry

 

Community Support Team _ Barry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
MccorryIT
Level: Powered On

Re: Rename file in ODFB when the file is modified

Hi Barry,

 

The solution working fine. Got another question, for the filename, how do i include the original filename with timestamp(date only)? For example, the original file abcd.xlsx, after modified the flow create new file abcd_18-12-2018.xlsx and delete the abcd.xlsx . Next modified, the flow create new file abcd_20-12-2018 and delete the abcd_18-12-2018.xlsx .

Community Support Team
Community Support Team

Re: Rename file in ODFB when the file is modified

Hi @MccorryIT,

 

Ideally, if the initial names of all the files in your specified folder do not contain any symbols, there may be ways to achieve your needs.

By judging whether the file name of the currently modified file contains "_", if it is not included, the current date can be directly added to the file name.

If it does, you need to replace the date with the current date.

If you have the specified folder, it is recommended to select the corresponding folder instead of Expression when configuring Folder Path.

Formula reference:

 

Condition:

@and(not(contains(triggerBody()?['DisplayName'], '_')),not(equals(triggerBody()?['IsFolder'], true)))

Create file:

replace(triggerBody()?['Path'],triggerBody()?['DisplayName'],'')

concat(first(split(triggerBody()?['Name'],'.')),'_',utcNow('dd-MM-yyyy'),'.',last(split(triggerBody()?['Name'],'.')))

original:

first(split(triggerBody()?['Name'],'_'))

extension:

last(split(triggerBody()?['Name'],'.'))

Create file 2:

replace(triggerBody()?['Path'],triggerBody()?['DisplayName'],'')

concat(outputs('original'),'_',utcNow('dd-MM-yyyy'),'.',outputs('extension'))

Image reference:

50.PNG

Note that the Delete file action is not configured in If no branch. This is also my confusion. If configured, all files will be deleted.

 

Edit:

This method still has problems. It seems that the Create file action in the IF no branch is similar to the Modified file. It is not creating a new file. I am improving.

 

Best Regards,

Barry

 

Community Support Team _ Barry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
MccorryIT
Level: Powered On

Re: Rename file in ODFB when the file is modified

Thanks for your support. Hope to hear from you soon.

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

firstImage

Incoming: New and improved badges!

We've given our badges an overhaul and also added some brand new ones!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Power Automate Community Video Gallery!

Top Kudoed Authors
Users Online
Currently online: 197 members 5,361 guests
Please welcome our newest community members: