“I don’t want Power Automate to replace the existing file, I want to update it. To upload a new version of that file, not to delete the original one.”
When creating, moving or copying file in Power Automate, you might feel limited if you want to update an existing file. ‘Create file’ doesn’t offer any solution, if file with the name already exists, it’ll just fail. ‘Move file’ or ‘Copy file’ will at least offer you some options and not fail right away, but the update is still missing. You can replace (delete) the old file, or you can upload the new file with a different name, ..or fail. But what if you want to keep the file and just update it? To upload a new version of the file?
‘Update file’ action
It’s doable, but it’s not a simple configuration in an action, you must build the functionality by yourself. It’ll require using the ‘Update item’ action to update the file content.
‘Update file’ action allows you to update the content of an existing file. You provide the ‘Identifier’ of the file and the new content, and Power Automate will create a new version of that file with the updated content. But it’ll require some preparations in the flow before you can use that action.
Check if file exists
First step is to check if the file already exists. You want to update only existing file, if the file doesn’t exist you can’t update it.
The simplest solution is to use the behaviour mentioned before: if file exists, ‘Create item’ action will fail. And you can configure the same behaviour also for ‘Copy file’ and ‘Move file’ by selecting ‘Fail this action’ if file is already there.
You can use the Create/Copy/Move file action failure as the trigger for the file update section. You’ll set the next action’s ‘Configure run after’ to run only if the previous action ‘has failed’.
Get the existing file ‘Identifier’
Since you need the ‘Identifier’ of the existing file, you must search for it in the destination site/library. ‘Get files (properties only)’ is the action running only if the creation/move/copy failed. Use a filter query to filter by the file name you just tried to use. The output will be an array with a single file.
FileLeafRef eq 'FileNameWithExtension'
Get the new file ‘content’
‘Identifier’ of the existing file is only one of the inputs for ‘Update file’ action, the next one is ‘File Content’. Content of the new file that should replace the content of the existing file, which you’ll get with the ‘Get file content’ action. Don’t forget, it must be content of the NEW file.
Update the existing file
Now it’s the time to use the ‘Identifier’ of the existing file and the ‘File Content’ of the new file in the ‘Update file’ action. Don’t worry about the ‘Apply to each’, it’s added because the ‘Get files (properties only)’ action returned an array., but since it’s an array with a single file, it’ll run only once.
Continue in the flow
This step depends on the design of your flow. If your flow ends with the ‘Update file’ action, you can skip it.
But if your flow should continue, you must use the ‘Configure run after’ once more after the file is updated. The file updating part of the process will run only if there’s an error during creation/move/copy, otherwise it’ll be skipped. In such situations, you must tell the flow where to continue even if the update is skipped. To do that, configure the next action to run also when action ‘is skipped’. It’s similar solution as when you need to disable a part of a flow.
The solution above is build on two main ideas: first, action ‘failure’ is not always a problem you must solve. In this post you can see that action ‘failure’ can be part of the flow, that you can use it to achieve the goal.
And the second idea: don’t depend only on a single action and its configuration. If some functionality is not available directly, you can probably build it by yourself combining multiple other actions.
15 thoughts on “How to update (not replace) an existing file in Power Automate”
So I created a similar flow to update the contents of a word file in my SharePoint library. The flow runs successfully but the content of the file does not get updated. Would appreciate some help.
I’d check if the flow really went through all the actions or if some were skipped like here: https://tomriha.com/why-has-the-power-automate-condition-grey-colour-in-the-run-history/. Maybe the flow didn’t find the file to update.
How do you get the “Identifier” in the “File to Move” field in the “Move File 2” step before the “Get Properties” step? If I insert the Move File step before the Get Properties step, I cannot get the Identifier. And If I insert it after the Get File Properties and insert “Identifier”, it automatically goes inside an “Apply to Each” and I am unable to move the Move File step to before the Get file (properties only) step.
Sorry, the earlier email id I gave is wrong, I noticed the mistake just as I clicked on “Add Comment”.
The correct id is email@example.com
Tom, what is the trigger action for this flow? What are the steps before the “Move File 2” step?
the trigger is up to you, it can be ‘When a file is updated’ to synchronise libraries or ‘When an item is modified’ to backup item attachments, it’s not important for the solution.
The ‘Identifier’ in ‘Move File 2’ is the identifier of the file you want to move, the 1st, original file. The ‘Get file (properties only)’ will give you the ‘Identifier’ of the 2nd file which you can then use to get the content of the new file.
Thank you for the quick response. I am very new to Power Automate and would be very grateful for your help. How do I get the identifier of the file I want to move – the 1st original file? And why is the Move File showing as “Move File 2”?
Take a look on this old article on copying files, that describes a full process, the only difference is that the article uses ‘Copy file’ instead of ‘Move file’.
It’s called ‘Move File 2’ because the screenshot is only a part of a bigger, more complex process that already had ‘Move File’ action. Since 2 actions can’t have the same name in Power Automate, it automatically added 2 to the 2nd one.
Hey, Tom thank you for your assistance. I had to bulk upload about 5k revision documents and also update their metadata. This solution of yours gave me the core and I built upon it.
Thanks again for the help.
My Update File action is failing with the following “A file or folder with the name ‘TestingDoc.docx’ already exists at the destination.”. I didn’t think this was supposed to happen. Help!! 😀
that’s fine, that’s the trigger for the updating part of the flow. If you configured it correctly it’ll show this error, but then it’ll continue with the update. But if the flow still ends in an error status, then there’s a problem somewhere later probably.
Good Content! Thanks! Still works in Nov 2022!
I’m trying to use this flow as a template for a file update action that I need to carry out in a document library. The flow is “completing”, i.e. all green ticks, but the file content isn’t being updated, and I’m not receiving a notification email (the step after the content update step) to say that the content has changed. I suspect that the reason for the lack of output is that the file type I am trying to amend is PDF (effectively to update the content of the PDF when the database that is the source of the record is updated) – do you know if this kind of flow will always result in a lack of action when PDF is the concerned file type? I know it’s terribly hard to manipulate PDFs in Power Automate, especially without use of Premium connectors…
I don’t think there should be any problems with PDF files, you just load the file binary content and replace it in another file. I’d check the flow run history, if all the actions really did their work (there’re no greyed out actions) because if you’re not receiving an email then the ‘Send an email’ action probably didn’t even run.
Why not simplify things further and simply put the Update file step before the Create file and configure the Create file step to run after the Update file step has failed? I believe that this is how the Power Automate folks intended us to use this configuration parameter… You can then delete all of the unnecessary steps such as Move file, Get files (properties only), Get file content and Apply to each.