Power Automate or Microsoft Flow delete all files in a folder

From this Microsoft Power Automate Tutorial, we will learn how to delete all files in a folder using Microsft flow or Power Automate. Also, we will discuss the below topics:

  • Power Automate delete files in a folder
  • Microsoft flow delete all files in document library
  • Microsoft flow delete all files in subfolder
  • Microsoft flow delete a perticular files
  • Power Automate delete files older than

Microsoft flow delete all files in SharePoint document library

In this section, we will see how to delete all files in a SharePoint document library using Power Automate flow.

For example, there are different kinds of files such as image files, PDFs, word files, excel files, etc stored in a document library like below:

Microsoft flow delete all files in SharePoint document library
Microsoft flow delete all files in the SharePoint document library

Let’s create a flow that will delete all files from the SharePoint document library.

Go to https://india.flow.microsoft.com/ and sign in with your Microsoft account. Then click on +Create > Go to Instant cloud flow.

Power Automate delete all files in SharePoint document library
Power Automate delete all files in the SharePoint document library

Here we will select Manually trigger a flow that will allow controlling the flow from mobile using a button. Also, give a name to the flow i.e. Delete all files in the SharePoint document library. Click on Create.

delete all files in SharePoint document library
Delete all files in the SharePoint document library

Now our flow is created like below:

delete all files in SharePoint document library using flow
Delete all files in SharePoint document library using flow

Next, click on +New step > search for Get files(properties only) > add this action to the flow. It will get all the files from the SharePoint document library. In this section, we will specify the site address and the library name.

Power Automate how to delete all files in SharePoint document library
Power Automate how to delete all files in the SharePoint document library

After getting all the items from the document library, now we will add an action to delete those files at a time.

For this, Click on +New step > Delete files(Search the action) > Add this action to the flow.

Similarly, here we have to specify the Site address. In the File identifier, select the identifiers from the get files properties. We can see it will create an Apply to each loop automatically.

Flow to delete files in SharePoint Document Library
Flow to delete files in SharePoint Document Library

Now our flow is ready to run. Let’s save the flow and test it manually. We can see the flow ran successfully as there is no issue. If there will be an issue then it will show that error here.

Delete all files of a SharePoint library using Microsoft flow
Delete all files of a SharePoint library using Microsoft flow

Now, when we will open our document library, we can see it will delete all the files from here.

Flow to delete all files in SharePoint document library
Flow to delete all files in SharePoint document library

This is how to delete all the files from the SharePoint document library using Power Automate flow.

Read Power Automate add days to date

Power Automate delete files in a folder

Here we will see how to delete all files from a folder in SharePoint document library. For example, there is a folder in the document library that contains several PDF files like below:

Power Automate delete all files in a folder
Power Automate delete all files in a folder

Now we will create a flow that will remove all files from this PDFs folder. Let’s create a flow on Power Automate to implement this. The following steps are:

Step-1:

Lets start the flow by triggering it manually that we have created in previously. After that, we will add action to get all the files from the SharePoint document library.

Click on +New step > Search the Get files(Properties only) action > Add it. Here we will set the SharePoint site address and the document library name.

Microsoft flow delete all files in a folder
Microsoft flow delete all files in a folder

Step-2:

Next, we will add an action i.e. Filter array where we will set the properties such as:

  • From– Value (Select from the Get files)
  • Value– Folder path(select from the Get files)
  • Operator– is equal to
  • Value-Shared Documents/PDFs/

Note:

The Shared Documents is the name of the SharePoint Document library name and PDFs is the name of the folder of the document library name.

Delete all files in a folder using Flow
Delete all files in a folder using Flow

Step-3:

Under this Filter array action, we will add an ‘Apply to each’ action for looping where we will use the body as output from the previous step i.e. from the Filter array.

Inside this loop, we will add another action to delete the files from the provided folder. Here we will specify the site address and in file identifier, set the below expression.

item()?['{Identifier}']
 Flow to delete all file in one folder in a SharePoint library
Flow to delete all files in one folder in a SharePoint library

Now our flow is ready to run. Let’s save this flow and test it Manually.

SharePoint automation to delete files in a folder
SharePoint automation to delete files in a folder

Now we can see the flow ran successfully as there is no issues; otherwise it will show the error message:

Power Automate delete items in a folder
Power Automate delete items in a folder

When we will check the folder in a document library, we can see all the files got deleted.

How to delete files in a folder power automate
How to delete files in a folder power automate

This is how to delete all files in a folder using Power Automate.

Read Power Automate Increment Variable

Microsoft flow delete all files in subfolder

Here we will see how to delete all files in the subfolder in the SharePoint document library. For example, we have a subfolder inside a folder of the document library. There are different kinds of files inside the subfolder such as word files, pdf files, images, etc.

Let’s create a Power Automate flow that will delete all the files in that subfolder. For this, the following steps are:

Step-1:

After triggering the flow manually, we will add the action ‘List folder‘ that will return files contained in a SharePoint folder. Here we will set the properties like below:

  • Site Address- Specify your SharePoint site address.
  • File identifier- /Shared Documents/PDFs/office (Specify the sub folder path)

Note-

Here the Shared Document is the name of the SharePoint document library where the PDFs is the name of the folderand the subfolder is office.

Power Automate delete all files in a subfolder
Power Automate delete all files in a subfolder

Step-2:

Next, we will add an action to delete the files from the subfolder.

Click on +New step > Delete file (under SharePoint) > Add this action to the flow. Here we will set the properties like below:

  • Site address- Specify your SharePoint site address
  • File Identifier- Select ID from the List folder.

We can see it will create an Apply to each loop inside the flow.

How to delete files in a subfolder using Power Automate
How to delete files in a subfolder using Power Automate

Let save the flow and test it manually. We can see the flow ran successfully without any issues.

Microsoft flow delete all files in subfolder
Microsoft flow delete all files in subfolder

We can see all the files got deleted from the subfolder of the Document library.

Power Automate delete all files in a document library subfolder
Power Automate delete all files in a document library subfolder

This is how to do Power Automate delete all files in a document library subfolder.

Read Power Automate copy list item to another list with attachments

Power Automate delete files in SharePoint folders based on files name

Here we will see how to delete files in the SharePoint folder based on files types. Also, we will see how to delete a specific file in the SharePoint folder using Power Automate flow.

Example-1: Power Automate delete a specific file in the SharePoint folder

For example, there is a folder in the SharePoint document library having some different kinds of excel files, images, etc.

Delete a specific file in the document library
Delete a specific file in the document library

Let’s create a flow that will delete a specific file from the whole file. For example, we want to delete the excel file of Data i.e. Data.xslx. For this, the steps are:

Step-1:

In Power Automate, after triggering the flow manually, we will add an action that will return all the files contained in a SharePoint folder.

Click on +New step > List folder. Add the parameters like below:

  • Site Address– Specify the SharePoint site address
  • File Identifier-/Shared Documents/Reports

Note-

Here the Shared Document is the name of the Document library name and the Reports is one of the folder name of the document library.

Power Automate delete file based on file name
Power Automate delete file based on filename

Step-2:

Next, we will add an action ‘Filter array‘ using the Body as an output from the List folder.

Click on +New step > Filter array. Also, set the condition using the below values:

  • choose a value(first)- Name (select from List folder)
  • Opertor- is equal to
  • choose a value(second)- Data.xlsx
Flow to delete a specific file in the folder
Flow to delete a specific file in the folder

Step-3:

After filtering the files, we will add an action to delete that specified file from the document library. For this, we will add an action i.e. Delete file(under SharePoint).

Click on +New step > Delete file. Here also, we will set the Site address and in the File identifier, we will use the ID from the filter array.

We can see it will create an Apply to each loop so that it will check the files (one by one) in the document library and delete the specified file.

Power Automate delete a specified file based on file name
Power Automate delete a specified file based on filename

Now our flow is ready to run. Let’s save it and make it run. We can see it ran successfully without any errors.

Microsoft flow delete a specified file in the document library
Microsoft flow delete a specified file in the document library

Let’s check the folder and we can see the Data.xlsx file got deleted from the document library.

Microsoft flow delete a specific file based on name
Microsoft flow delete a specific file based on name

This is how to delete a specific file in the SharePoint folder using Power Automate.

Read Power Automate save email attachment to SharePoint

Example-2: Power Automate delete multiple files in the folder based on files types

In this example, we will see how to delete multiple files based on files name or extensions. For example, we want to delete all the excel files from the Report folder in the SharePoint Document library.

Let’s create a flow to implement this. The following steps are:

Step-1:

After initializing the flow manually, we will add an action to get the folder from the document library.

Create +New step(under the initialize the flow manually)> List folder. Set the parameter like below:

  • Site address- Specify your SharePoint site address
  • File Identifier- /Shared Documents/Reports (Specify your folder path)

Note- Where Shared Documents is the document folder and the Reports is the folder name.

Power Automate delete multiple files in the folder based on files name
Power Automate delete multiple files in the folder based on files name

Step-2:

In the next step, we will add an action i.e. Filter array using the Body as an output from the List folder.

Click on +New step > Filter Array. Also, set the condition using the below values:

  • choose a value(first)- Name (select from List folder)
  • Opertor-contains
  • choose a value(second)- .xlsx

It will filter the files that contain ‘.xlsx‘.

Delete multiple files in the folder based on files name using Flow
Delete multiple files in the folder based on files name using Flow

Step-3:

Now we will add the final step. In this step, we will add an action that will delete the filtered files. Click on +New step > Delete file. Also, set the parameters like below:

  • Site address- Specify the SharePoint site address
  • File identifier- Select ID from filter array. We can see it will create an Apply to each loop so that it will delete the filter files one by one.
Microsoft flow to delete multiple files in the folder based on files name
Microsoft flow to delete multiple files in the folder based on files name

Now our flow is ready to run. Let’s save it and test it manually, then click on Run flow. We can see our flow ran successfully without any issue.

MS flow Delete multiple files in the folder based on files name
MS flow Delete multiple files in the folder based on files name

Let’s check our folder in the document library and we can see all the excel files got deleted:

Microsoft flow to remove multiple files in the folder based on files name
Microsoft flow to remove multiple files in the folder based on files types

This is how to remove multiple files in the folder using Power Automate.

Read Power Automate get items examples

Power Automate delete files older than

Here we will see how to delete files that are older than 2 days from the created date in a SharePoint document library. For example we have some different kinds of files in a document library like below:

power automate delete files older than
power automate delete files older than

Now we will create a flow that will delete files that are older than 2 days from the document library. For this the following steps are:

Step-1:

Let’s start the flow by triggering it manually. Then we will add an action to get the files from the document library.

Click on +New step > Get Files(Properties only) > Add this action to the flow. Set the SharePoint site address and the Library name.

Delete files older than 2 days in document library using flow
Delete files older than 2 days in the document library using flow

Step-3:

Next, we will add an action i.e. Convert time zone that will covert the Created time(on which time the file was created in SharePoint document library) to UTC.

Click on +New step > Convert time zone. Here we will set the parameters like below:

  • Base time- Created (select it from the Get files)
  • Format string- Short date pattern – 6/15/2009 [d]
  • Source time zone- (UTC-08:00) Pacific Time (US & Canada)
  • Destination time zone- (UTC) Coordinated Universal Time

After choosing the base time, we can see it will create an Apply to each loop. That will convert the timezone of the files one by one.

Deleting Files older than 2 days in the SharePoint document library
Deleting Files older than 2 days in the SharePoint document library

Step-4:

Now, we will set the logic through a condition. So here, we will add a Condition action inside the loop, that will check the file’s created date is less than 2 days of today’s date.

Click on +add an action > Condition control. Set the parameters like:

  • Choose a value(First)- Converted time (from Convert time zone)
  • Operator- is less than
  • Choose a value(Second)- Set the below expression that will return the date which is older than 2 days from today
addDays(utcNow(),-2,'MM/dd/yyyy')
Delete files older than 'X' days from Document library using Flow
Delete files older than ‘X’ days from Document library using Flow

If the condition is satisfied then it will move to the if-yes part i.e. it will delete the files from the SharePoint document library.

Go to the IF- yes part, Click on +add an action > Delete files. Set the Properties like below:

  • Site address- specify your SharePoint Site address
  • File Identifier- Identifier(select it from Get files)
Delete All Files Older than 2 Days in a Document Library
Delete All Files Older than 2 Days in a Document Library

Now our flow is ready to run. Let’s save the flow and run it as Manually. We can see it ran successfully without any errors.

Delete files after x days using Power Automate flow
Delete files after x days using Power Automate flow

Let’s check the document library. We can see the files got deleted that are older than 2 days from the today’s date.

How to delete files older than X days automatically using flow
How to delete files older than X days automatically using flow

This is how to delete files older than 2 days automatically using flow.

Related Power Automate tutorials:

Conclusion

From this Power Automate tutorial, we learned how to delete files from the document library using Microsoft flow or Power Automate. Also, we discussed these topics:

  • How to delete all files in SharePoint document library using Microsoft flow?
  • How delete files in a folder of the document library using Power Automate?
  • How to delete all files in subfolder using Power Automate?
  • How to delete files in SharePoint folders based on files types using Power Automate?
  • How to delete a specific file in the SharePoint folder using Microsoft flow?
  • How to delete files older than 2 days using flow?
>