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

Deleting files from multiple document libraries

Basically what I want to do is to delete all the files from 20 libraries.  It's basically a cleanup flow.  I don't want to delete the libraries themselves but I want to delete the files / folders inside each library.

I can do this by manually doing a get items per library and then using the apply to each and then delete item action card and it works but what I want to do is to have a simpler flow that would read a list that has each document library name in it.  Do a get items based on that list.  Then return those library names to use in the next get items that would get the items in each library and then from there use the delete item action card to delete all the files.

It seems simple enough in my head but when I attempt to do the lookup of the document library names in the list that works fine and I return the output of all 20 libraries.  Then when I take those libraries and do a get items for each library I can do that and it works, BUT when I do the delete action card it doesn't allow me to select any of the output from the 2nd get items action card.  It only show's the first.  I'm new to flow so I'm sure I'm just doing something wrong but for the life of me I can't see what it is and why flow isn't allowing me to use any of the output listed from the 2nd get items to delete them.

Annotation 2019-03-08 183350.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Support Team
Community Support Team

Re: Deleting files from multiple document libraries

Hi @Itprofessional ,

 

Do you mean that the Departments list contains the Library name that needs to be emptied of files?

Then, according to these names, all the files in the current Library that need to be deleted.

 

  • All you have to do is add an Apply to each outside of “Delete item“ action and use the value of Get items 2 as the traversal.
  • And use "items('Apply_to_each_2')['ID']" to get item ID of the current file or folder. If Flow is executed, an error may occur, which is normal.

 

Delete item action does not discriminate between files or folders, if the folder is deleted first, the files inside will also be deleted. When the ID of the file inside the folder is traversed, "Item not found" is displayed.

You could ignore this error and check directly if the files have been deleted.

 

Image reference:

5.PNG

Please take a try.

 

Best Regards,

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.

View solution in original post

2 REPLIES 2
Highlighted
Community Support Team
Community Support Team

Re: Deleting files from multiple document libraries

Hi @Itprofessional ,

 

Do you mean that the Departments list contains the Library name that needs to be emptied of files?

Then, according to these names, all the files in the current Library that need to be deleted.

 

  • All you have to do is add an Apply to each outside of “Delete item“ action and use the value of Get items 2 as the traversal.
  • And use "items('Apply_to_each_2')['ID']" to get item ID of the current file or folder. If Flow is executed, an error may occur, which is normal.

 

Delete item action does not discriminate between files or folders, if the folder is deleted first, the files inside will also be deleted. When the ID of the file inside the folder is traversed, "Item not found" is displayed.

You could ignore this error and check directly if the files have been deleted.

 

Image reference:

5.PNG

Please take a try.

 

Best Regards,

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.

View solution in original post

Itprofessional
Level: Powered On

Re: Deleting files from multiple document libraries

That worked! Thanks!

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: 192 members 5,373 guests
Please welcome our newest community members: