web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Auto delete files in S...
Power Automate
Unanswered

Auto delete files in SharePoint subfolders based file name

(0) ShareShare
ReportReport
Posted on by 15

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

Categories:
I have the same question (0)
  • tom_riha Profile Picture
    10,185 Most Valuable Professional on at
    Re: Auto delete files in SharePoint subfolders based file name

    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.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Tomac Profile Picture

Tomac 497 Moderator

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 477 Super User 2025 Season 2

#3
chiaraalina Profile Picture

chiaraalina 242

Last 30 days Overall leaderboard