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

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. 

8 REPLIES 8
Super User
Super User

Re: Delete subfolder or all subfolder contents every night

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:

https://plumsail.com/docs/documents/v1.x/getting-started/sign-up.html#generate-api-key

 

Then connect it and use it like this:

https://plumsail.com/docs/documents/v1.x/flow/how-tos/documents/use-regex-match-to-extract-values.ht...

 

You'll get something like this:

regex-match-flow.png

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.

Cheers
Manuel

jmathur
Level: Powered On

Re: Delete subfolder or all subfolder contents every night

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. 

 

2019-11-13_12-50-12.png

 

I have included screenshots below of the current flow. 

 

2019-11-13_12-51-12.png

 

 

Super User
Super User

Re: Delete subfolder or all subfolder contents every night

HI @jmathur 

 

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

 

Try the following expression

Workspace(?s)(.*)\/Output\/(?s)(.*)\/Temporary

If I check on regex101.com I get a valid pattern:

https://regex101.com/r/B2kzKI/1

 

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.

Cheers
Manuel

 

jmathur
Level: Powered On

Re: Delete subfolder or all subfolder contents every night

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: 

 

2019-11-15_9-54-46.png 

 

 

 

Super User
Super User

Re: Delete subfolder or all subfolder contents every night

Hi

 

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.
Cheers
Manuel

jmathur
Level: Powered On

Re: Delete subfolder or all subfolder contents every night

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. 

 

Capture.PNG

 
Super User
Super User

Re: Delete subfolder or all subfolder contents every night

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?

 

Try:

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.

Cheers
Manuel

 

jmathur
Level: Powered On

Re: Delete subfolder or all subfolder contents every night

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" 

 

2019-11-20_17-10-25.png

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: 

 

2019-11-20_17-12-57.png

 

 

Helpful resources

Announcements
firstImage

Better Together Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

firstImage

Incoming: New and improved badges!

Look out for new contribution recognition badges coming SOON!

firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Community Summit North America

The top training and networking event across the globe for Microsoft Business Applications

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