Skip to main content

Notifications

Power Automate - General Discussion
Answered

Automate to delete sharepoint folders and files after xx days... flow successfully deleted all the folders and files but still failed with an 'Item not found' error

(0) ShareShare
ReportReport
Posted on by 37

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.

TC416_0-1685372054716.png

TC416_1-1685372803420.png

 

Thanks for any advice. 
T.C.

  • TC416 Profile Picture
    TC416 37 on at
    Re: Automate to delete sharepoint folders and files after xx days... flow successfully deleted all the folders and files but still failed with an 'Item not found' error

    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.

  • Verified answer
    ManishSolanki Profile Picture
    ManishSolanki 15,075 on at
    Re: Automate to delete sharepoint folders and files after xx days... flow successfully deleted all the folders and files but still failed with an 'Item not found' error

    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:

    ManishSolanki_0-1685417549547.png

     

    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

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

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,434

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,722

Leaderboard