Showing results for 
Search instead for 
Did you mean: 
Helper I
Helper I

Delete subfolder or all subfolder contents every night

I'm part of a team that uses a tool which automatically creates hundreds of unnecessary files that are clogging our SharePoint library when they are generated. I want to build a flow that will delete these files every night. My trouble is that these file paths are somewhat unique, so I can't tell the flow to just delete everything that matches a specific file path. 

The files that need to be deleted are in a folder path akin to the following:


Workspace/<project name>/<project subset>/<version>/Output/<username>/Temporary 


where everything in <> is a variety of values, and cannot be specifically determined by something other than a wildcard character. 


Any solutions? I'm thinking that my file path would look something like Workspace/*/Output*/Temporary, but can't even get the Get Files (properties only) action to return all the files in the library. 

Super User
Super User

Hi @jmathur 


Regular Expressions would be ideal to achieve this. To do this, Power Automation has a component called "Plumsail" that can help with this.


To be able to use, you need an API key that you can get here:


Then connect it and use it like this:


You'll get something like this:


Then you can define your expression so that you define the folder structure to delete.


Is this what you need? If not, please let me know, and we'll try to figure this out together.


If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.


Hi @manuelstgomes 


Thank you for your reassurance! 


I do need some step by step assistance. I got the API key and added the Regular Expression Match, but I don't understand how to formulate the pattern. As I said before, all of the folders I will want to delete will have a file path that, at the end, includes: Workspace/<any number of sub folders here>/Output/<computername>/Temporary. I want to delete all Temporary folders and all its contents. 




I have included screenshots below of the current flow. 





HI @jmathur 


Not a big REGEX expert myself but let's try to figure this out.


Try the following expression


If I check on I get a valid pattern:


Is this what you need?


If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.



Hi @manuelstgomes 


I think we are a bit closer but it's hard to tell. My new problem is that the dynamic content Folder Path doesn't seem to be picking up any of the documents I'm trying to find. I'm wondering if it's because the folder path of the docs I'm trying to delete is too long? When I do a download of the output and do a search on Output or Temporary, neither one shows up in any instance. The library I'm pulling from does have thousands upon thousands of files... is there any way to adjust the Get files (properties only) action to do a better job at selecting which files to get properties for? Otherwise I think that it doesn't pull anywhere close the data we need to filter on.


All 100 instances came back with outputs similar to the below: 








If it's not finding the folders then the regular expression is incorrect. But the folder bellow is a bit different than the structure that you mentioned before. Do you need to pick those ones too?

I think our next course of action is to reduce the number of records. You have, in your original post 5000, but already reduced to 100 correct?

I would recommend now to speed things up to create a view in SharePoint with only the information that you need. Create minimal information possible so that we have less information going back and forward. Then add that column in the advanced part in "Limit Columns by View".

Let's try this and see where we get.

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Hi @manuelstgomes 


So I created a view and a choice column both called Temporary, and set twelve documents to have the choice column set to Yes. When I ran the flow, it didn't pick up the documents. See below. What am I missing? Even so, we would also need to find a way to automatically tag all those Temp files so that they would be included when the flow runs nightly. 




HI @jmathur 


The issue is in the "Filter Query". It's trying to find a Text column that contains "Yes", but you have a "Yes No" column correct?



Temporary eq 1


If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.



hi @manuelstgomes 


Thank you for the idea. I tried it (for a column that is a Yes No column and for one that is a text column) and neither one yielded results. I think it's because the files are so deeply buried that the flow was having trouble finding them, so I used a Modified asc odata filter and that helped bring up the Temporary files to the top of the pulled results. 


However, even though it's a Get Files Properties, it's only identifying folders! I'm not sure why. There are a lot of folders certainly but surely it would pull the files within those folders as well? See below, "FilenameWithExtension" is "TOCs" not something like "TOCS.pdf" 



It's causing a problem in my delete files action because there are no files for it to find as of yet. I am happy to have it delete all the folders under Temporary (I have added a condition that says "If file path contains Output" and "If file path contains Temporary"), but I don't know how to do that. Currently the Flow looks like this: 





Helpful resources

UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Users online (2,621)