I have a bunch of subfolders in SharePoint and I am wondering about how would I go about automatically deleting files within them if the folder name doesn't match the beginning part of the file name? For example in my screenshot, the sub folder name is "J0000-1002", so I would remove any file that doesn't start with "J0000-1002". The sub folders will have different names so this would need to be dynamic based on the sub folder name.
I am fairly new to Power Automate and was wondering if this is possible. I was thinking of using the trigger "When a file is created or modified" but not sure how to apply it to multiple sub folders. Any help would be appreciated, thanks!
Hello @overhead_press2 ,
In SharePoint, there is a concept called ServerRelativeUrl which means a URL for a resource in SharePoint which starts with a "/" and excludes the domain name.
For e.g. Let's assume you have a file File1.xlsx in a SharePoint Library, the actual Path (Or absolute URL) to this File will be "https://yourdomain.sharepoint.com/sites/MySite/MyLibrary/File1.xlsx" and the Server Relative URL will be "/sites/MySite/MyLibrary/File1.xlsx".
Now going back to my Reply above, In Step 3 we are getting all the Folders including Sub Folders in the Library, when we send the http call to SharePoint, it returns a JSON Object which contains metadata for these Folders (Check the Output of Send http request to SharePoint action when you implement this solution) which includes ServerRelativeUrl for each folder.
We are then using this URL to query and get all the files within each of the Folders retrieved in Step 3.
I hope this answers your question, feel free to post any other questions you may have.
Thank you so much for the in-depth reply, one question is for step 5, how would I get the server specific url? Sorry I am relatively new to SharePoint, thanks!
Hello @overhead_press2 ,
In the below steps I will show you how you can get all the Folders (including Sub Folders), then traverse each Folder to get Files within them which satisfies your condition and delete them.
Hope this helps you out!
Please give a Kudo or mark this reply as Solution if you found it helpful.