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

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
Community Support
Community Support

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

3 REPLIES 3
Community Support
Community Support

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

That worked! Thanks!



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.

 


Hello,

 

There is no other way than ignoring the "Item not found" error ? It's not a very suitable option for me.

 

Thanks,

David

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

MPA Community Blog

Power Automate Community Blog

Check out the community blog page where you can find valuable learning material from community and product team members!

Top Solution Authors
Top Kudoed Authors
Users online (9,148)