Hi, I have a Sharepoint folder in a path on Sharepoint like - Shared Documents/My Folder/Output/....
This output folder has lots of folder in it with files in each folder. I have to delete all folders in Output folder. Please suggest.
The method I provided will ignore the subfolders when deleting the folder, because when deleting the parent folder, all the contents inside will be clear, including subfolders. Every folder and file will have an item ID, and we rely on it for deletion.
@v-bacao-msft - Only thing I was initially in doubt was that when deleting child folder, I am using delete item where I am providing List name as Documents and Id as folder ID which is a number, I hope in Sharepoint each folder has this unique ID number as in delete item I dont have option to provide any full path, hence it will delete item in Documents library with that ID number. Please confirm if you know about this?
@v-bacao-msft - Thanks a lot for your response. When getting child folder in parent output folder, I am providing the right path of parent output folder in Limit Entries to folder field. With this I believe the files entire scope of delete will be limited to this parent output folder.
Once I get all folder (child folder) of parent output folder - I am looping on each of it and deleting files from each child folder to avoid error (till folder is not empty it cant be deleted). Once all files from child folder are deleted I am deleting child folder. So on a high level flow looks like -
Get all child folders in Parent folder
Loop on child folders
Get Files in Child folder
Loop on files in child folder
Delete file from child folder
Next
Delete Child Folder
Next
Hi @mayankgoyal1984 ,
I think @yashag2255 's suggestion is correct. Please pay attention to whether these folders contain important files to avoid accidental deletion.
In addition, you could refer to the screenshot below to configure Flow:
Errors similar to "item not found" may appear when Flow is running. You can ignore these errors. Because the Get files action will get the subfolder and the files in it, when Delete item deletes the subfolder, it will also delete the files in the subfolder, so when traversing to the files in the subfolder, an error will be reported. This is in line with expectations.
Hope this helps.
Best Regards,
Note that if there is a retention policy activated in SharePoint, Folders with data cannot be directly moved or deleted. You will have to use the list folder action and then check if the file is a folder or a file and if it is a file delete it and if not again list contents of that folder and so on.
Hope this Helps!
If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!
Michael E. Gernaey
497
Super User 2025 Season 2
David_MA
436
Super User 2025 Season 2
Riyaz_riz11
244
Super User 2025 Season 2