How to check if a file exists in the SharePoint document library in Power Automate?

In this Power Automate tutorial, we will see how to check if a file exists in the SharePoint document library in Power Automate.

Scenario:

We have a SharePoint Document Library called ‘Attachments‘ like below. When a new email arrived with an attachment. We will get the attachments, and then we will check if the file exists in the SharePoint folder, then we will delete the file and create a new file. If not exists, then it will directly create the file.

Below you can see the Attachment Library in SharePoint.

Power automate check if file exists

Now let’s create the flow to check if a file exists using Power Automate.

How to check if a file exists using Power Automate

Here we will see an example of how to check if a file exists using Power Automate.

Before creating the flow, create a document library in your SharePoint Online site, where you will save the attachments.

Step 1: Log in to Power Automate, then click on the +Create icon -> select Automated Cloud flow.

power automate check if sharepoint file already exists

Then provide the flow name, and select When a new email arrives(V3) action. Click on Create.

power automate check if sharepoint file already exists

Now, you can see that When a new email arrives action is added to the flow page. Then provide the below information:

  • Folder: Select Inbox, where you will receive an email.
check if a file exists in the SharePoint document library in Power Automate

Step 2: Next click on the +New step -> select the ‘Get attachment (V2)‘ action. Then provide the below information:

  • Message-Id: Select the Message-Id from the dynamic content.
  • Attachment Id: Select the Attachment Id from the dynamic content. That will automatically add Apply to each action
power automate check if file exists in sharepoint folder

Step 3: Next click on Add an action, and select the Get files (properties only) action. Then provide the below information:

  • Site address: Select or Provide the SharePoint site address.
  • Library name: Select or provide the SharePoint Library.
power automate sharepoint check if file exists

Step 4: Now we will check the file that exists in the folder, if exist then it will delete and create the file. Else it will only create a file.

See also  How to Convert String to Object in Power Automate

So, click on the Add an action -> select Condition action. Then provide the below information:

  • Choose a value: Select the Name as the value
  • Operator: Select the operator as is equal to
  • Choose a value: Provide the Name- Get file properties from dynamic content
check if a file exists in the SharePoint document library in Power Automate

If the condition is true, then in the If yes condition, click on Add an action -> select Delete file action. Then provide the below information:

  • Site address: Select or provide the SharePoint site address.
  • File identifier: Select the Identifier from the dynamic content. This will automatically add Apply to each action.

To create the file, click on Add an action -> select Create file action. Then provide the below information:

  • Site address: Select or Provide the SharePoint site address
  • Folder path: Select the folder path.
  • File name: select the File name from dynamic content.
  • File content: Select the Content Bytes from dynamic content.
How to check if file exists using Microsoft Power Automate

Now if the condition is false, then in If No part, click on Add an action -> select Create file action. Then provide the below information:

  • Site address: Select or Provide the SharePoint site address
  • Folder path: Select or provide the folder path
  • File name: Provide the name from dynamic content
  • File content: select Content Bytes from dynamic content.
How to check if file exists using Power Automate

Step 5: To run the flow click on Save and then click on the Test icon -> select Manually -> click on the Test button. Configure the connections -> click on Run flow -> click on Done.

You can send an email to the inbox of your Outlook, you can see your flow run successfully.

See also  How to Convert Data Table Columns to List in Power Automate Desktop?
power automate check if file exists in sharepoint folder

As our folder already contains a file, it will delete the file, and recreate the file in the folder.

power automate check if file exists in sharepoint

Conclusion

In this Power Automate tutorial, we saw an example that will check if a file exists or not in a SharePoint folder or document library using Power Automate.

You may also like:

>