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.