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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Issue deleting related...
Power Automate
Suggested Answer

Issue deleting related SharePoint files after folder deletion

(2) ShareShare
ReportReport
Posted on by 18

Hello everyone,

 

I am currently working on a Power Automate flow designed to automatically delete all related files stored in a SharePoint list when their corresponding folder is deleted in SharePoint.

My current setup involves multiple SharePoint sites: I have one SharePoint document library where the folders and documents are stored (including multiple subfolders). In addition, I maintain a separate SharePoint list on another site, which contains a consolidated view of all documents from all subfolders. which gets updated automaticaly when a new file is created.

My current implementation uses the “When an item is deleted” trigger. I then evaluate whether the deleted item is a folder by applying a condition (FSObjType = 1). If the condition is met, I proceed with “Get files (properties only)”, using the following filter query:

concat('startswith(FileDirRef,''', triggerOutputs()?['body/{Path}'], ''')')

This is intended to retrieve all files associated with the deleted folder. I then iterate through the results using “Apply to each” and attempt to remove each file via the “Delete file” action.

However, the flow does not behave as expected. In some cases, no files are deleted, while in others it appears that the flow fails to correctly identify the files associated with the deleted folder. I suspect the issue lies in how the relationship between the folder and its files is being determined (e.g., via path or reference fields).

I would greatly appreciate any guidance or best practices on how to reliably identify and delete all files associated with a folder upon its deletion.

 

Thank you in advance for your support.

Screenshot 2026-0...

Your file is currently under scan for potential threats. Please wait while we review it for any viruses or malicious content.

Categories:
I have the same question (0)
  • Suggested answer
    11manish Profile Picture
    3,333 on at
    For a multi-site architecture where a separate SharePoint list serves as the master document index:
    • Treat that list as the source of truth.
    • Store and filter by a dedicated FolderPath column.
    • When a folder deletion is detected, delete all list records where:
    startswith(FolderPath, DeletedFolderPath)

    rather than trying to discover the files from the document library after the folder has already been removed.
    This approach is more reliable, performs better, and scales well when dealing with nested subfolders and multiple SharePoint sites.
  • Jonihoni Profile Picture
    18 on at
    @11manish, is it posible t show me the flow via a screenshot? i dont realy get what you mean. That would help a lot!
     
  • chiaraalina Profile Picture
    2,425 Super User 2026 Season 1 on at
     
    Can you please add your screenshot directly? We cannot see it. Thanks!
  • Suggested answer
    Haque Profile Picture
    3,653 on at
    Hi @Jonihoni,
     
    When you use Get files (properties only) SharePoint action, can you please add a filter query that mathces the folder path prefix? For exmple: startswith(FileDirRef, 'folderpath'). This will retrieve all files under the folder and its subfolders. Then loop through the files and delete each one - that's what you already did.
     
     
    Please note that: FileDirRef is a built-in SharePoint file property representing the server-relative path of the folder containing the file - it tells where the file resides.
     
    And the 'folderpath' in the expression startswith(FileDirRef, 'folderpath') is a string you provide that corresponds to the folder path you want to filter files by. The server-relative path of the folder.
     
     
    For example, if the SharePoint site is https://contoso.sharepoint.com/sites/Example and the folder is Shared Documents/Projects/ProjectA, then the server-relative path might be: 
     
    /sites/Example/Shared Documents/Projects/ProjectA - We can use this full path (or the relevant part) as the 'folderpath' string in the filter query.
     
     
    References:
     
     
     

    I am sure some clues I tried to give. If these clues help to resolve the issue brought you by here, please don't forget to check the box Does this answer your question? At the same time, I am pretty sure you have liked the response!
     

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Valantis Profile Picture

Valantis 377

#2
11manish Profile Picture

11manish 279

#3
David_MA Profile Picture

David_MA 234 Super User 2026 Season 1

Last 30 days Overall leaderboard