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

Auto delete files in SharePoint subfolders based file name

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 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! 

1.png

1 REPLY 1
tom_riha
Super User II
Super User II

Hello @overhead_press2 ,

you can use the trigger 'When a file is created or modified'. For each document split the full document path to get the folder name (split by /, take the 2nd element from the end (length - 2, the last element is the file name)):

split(triggerOutputs()?['body/{FullPath}'],'/')[add(length(split(triggerOutputs()?['body/{FullPath}'],'/')),-2)]

 then split the file name by _ and take the first element, everything before the first underscore:

first(split(triggerOutputs()?['body/{Name}'],'_'))

Once you have these 2 values, you can compare if they're equal. If not, delete the file.



[ If I have answered your question, please Accept the post as a solution. ]
[ If you like my response, please give it a Thumbs Up. ]

[ I also blog about Power Automate solutions even for non-IT people. ]

Helpful resources

Announcements
Process Advisor

Introducing Process Advisor

Check out the new Process Advisor community forum board!

MPA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

Users online (44,749)