I have a flow that delete folders and files that after xx of days. The flow is correctly deleting the 10 items (3 folders, 3 subfolders, and 4 files) based on the set condition. However, the flow run status still says failed with an "Item not found" error. I debug using variable counter without delete action and it confirms that the condition set is correct.
Upon investigation it seems to throw the error after the first sucessful delete. I am suspecting may be the first successful delete has deleted the folder and all content within and thus when the flow try to delete the next item (items in the deleted folder), it's deleted already. However, if this is the situation, how come I am seeing all the correct folder an files are indeed getting deleted correctly in that SP library? I should only see that one folder deleted.
So the flow is working correctly and deleting the folders and files according to condition set...
But any idea/suggestion on how to resolve the failed error message?
Below are some screenshots for ref.
Thanks for any advice.
T.C.
I have traced and confirmed the error is becase when the delete action first deleted the parent folders, subfolders and content also get delete. However, 'Apply to each' still has those deleted objects in the query and attempts to delete again and encountered the error.
So, as you suggested, I have modified the workflow to delete only the files first and the delete only top level folders.
Thanks for the reply and suggestion.
Hi @TC416
You could separate the files & folders using 'Filter array' action. Firstly, loop and delete all files and once done then you could delete the folders. Here is an example to filter out files from result of 'Get files' action:
Similarly, you could filter out folder by Checking 'IsFolder' property for true value.
If this helps, please remember to give a 👍 and accept my solution as it will help others in the future.
Thanks