cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Baptiste_k97
Frequent Visitor

How to create a flow to delete files in SharePoint

Hello,

 

I'm looking to create a flow which would automatically delete files from a folder in a SharePoint library.

I would like to delete all files older than 7 days that are in a specific folder in my library with this rule.

 

Could you guide me through creating this flow?

Thanks. Baptiste.

 

 

15 REPLIES 15
Mira_Ghaly
Dual Super User II
Dual Super User II

@Baptiste_k97 

Please follow below steps :

1. you need a scheduled recurring flow to run daily 

 

2. Use Get Past time to get the time in the past by 7 days

 

3. Use the Get Files Action to get the files you want to delete from the folder

 

4. Expression on Filter Query Right hand side

formatDateTime(body('Get_past_time'),'yyy-MM-dd')

Note: Do not forget single quotes between the format expression

Mira_Ghaly_0-1621070513082.png

5. Apply to Each and Delete files

Mira_Ghaly_1-1621070714320.png

 

 

If this post helps you with your problem, please mark your as Accepted solution.If you like my response, please give it a Thumbs Up.

Blog: here

<p>Hello,</p>
<p>Thanks for your help. I'm having a problem in step 3 that makes my flux unusable.</p>
<p>How do I write the expression "Created It" before the filter query ?</p>
<p>&nbsp;</p>
<p><img src="https://nsa40.casimages.com/img/2021/05/15/210515060151323418.png" border="0" alt="" /></p>
<p>&nbsp;</p>
<p>I tried to write it by hand, but I get the error below when I run the stream.</p>
<li-code lang="markup">L'expression &laquo; Created It '2021-05-14' &raquo; n'est pas valide. Creating query failed.
clientRequestId: 7dd9422a-1f96-48ad-9d39-a73d6e315f4a
serviceRequestId: 7dd9422a-1f96-48ad-9d39-a73d6e315f4a</li-code>
<p>&nbsp;</p>
<p><img src="https://nsa40.casimages.com/img/2021/05/15/210515060009285867.png" border="0" alt="" /></p>
<p>&nbsp;</p>
<p>Thank you in advance for your reply.</p>
<p>Regards. Baptiste</p>

@Baptiste_k97

Is your column name in french in sharepoint?

Can you please add screenshot of your flow?

 

If this post helps you with your problem, please mark your as Accepted solution.If you like my response, please give it a Thumbs Up.

Blog: here

Yes @Mira_Ghaly my column name is in French in SharePoint.

Baptiste_k97_0-1621141394914.png

 

My flow :

Baptiste_k97_3-1621141901080.png

 

Baptiste_k97_2-1621141816865.png

 

@Baptiste_k97 

Can you use the French name in place of Created?

 

If this post helps you with your problem, please mark your as Accepted solution.If you like my response, please give it a Thumbs Up.

Blog: here
Baptiste_k97
Frequent Visitor

Hello,

I tried with the French name of my column but the result remains the same.

Baptiste_k97_0-1621181221360.png

 

Here is the column in question:

Baptiste_k97_1-1621181298887.png

 

Details of the error :

Baptiste_k97_2-1621181387329.png

 

@Baptiste_k97 

it is missing the Cree lt 'format...'

 

 

If this post helps you with your problem, please mark your as Accepted solution.If you like my response, please give it a Thumbs Up.

Blog: here

@Mira_GhalyI still have the same error.

In "Filter query" I put the following expression :

 

Cree it 'format...'

formatDateTime(body('Obtenir_l''heure_passée'),'yyy-MM-dd')

 

Baptiste_k97_0-1621234269986.png

 

@Baptiste_k97

Please use

Fieldnameinfrench lt

 

lt for less than

If this post helps you with your problem, please mark your as Accepted solution.If you like my response, please give it a Thumbs Up.

Blog: here
Baptiste_k97
Frequent Visitor

Hello @Mira_Ghaly 

I tried all the possibilities with the french name of my SharePoint column :

  • Créé + it + '...'
  • Modifié + it + '...'
  • Créé + '...'
  • Modifié + '...'

 

I still have this same error telling me that the "query filter" is invalid.

Baptiste_k97_0-1621262264253.png

 

It is not

It it is LT

If this post helps you with your problem, please mark your as Accepted solution.If you like my response, please give it a Thumbs Up.

Blog: here
Baptiste_k97
Frequent Visitor

As much for me @Mira_Ghaly  ...

Now I have an error at the last step of the flow : the files to be deleted are not found.

Baptiste_k97_0-1621355845205.png

 

I am told that the file to delete does not exist. 

I have the error message : "The file '/sites/WebsiteName/123' does not exist".

The last step of the flow doesn't take into account the folders between the site root and the file to be deleted.

Baptiste_k97
Frequent Visitor

Hello, My problem is still relevant. Thanks

MrNPP
Frequent Visitor

Hi there,
I was stuck on this too, with the last step saying the file did not exist.
You need to edit the last step to use the dynamic content "Identifier" not "ID".

sickaroll
New Member

Thanks for this, I was building relative file paths with concat() and getting nowhere, in spite of matching strings precisely with the 'browsed for' path (which doesn't show the /s as escaped, oddly). 
Identifier works very well and is much neater. 

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

New Ideas Forum MPA.jpg

A new place to submit your Ideas for Power Automate

Announcing a new way to share your feedback with the Power Automate Team.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

MPA Licensing.jpg

Ask your licensing questions at the Power Automate AMA!

Join Priya Kodukula and the licensing team, super users and MVPs to find answers to your questions on Power Automate licensing.

Users online (2,010)