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

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Flow - OneDrive - Dele...
Power Automate
Unanswered

Flow - OneDrive - Delete files older than 30Days in Folder

(0) ShareShare
ReportReport
Posted on by

Hi,

 

I cannot see this as an option in templates but can somebody help me design a flow that achives the following?

 

To automatically delete files in a Onedrive folder that are over 30days old?

 

Many thanks for the help

Categories:
I have the same question (0)
  • v-yamao-msft Profile Picture
    on at
    Re: Flow - OneDrive - Delete files older than 30Days in Folder

    Hi @Anonymous,

     

    According to your description, I created a flow likes below.

     

    The flow is triggered by a Button, followed by the OneDrive for Business action List files in folder, then add a Condition to check if the last modified time of the file is 30 days ago (as there is no dynamic content for Created date time, so I use last modified time instead). If yes, delete the file.

     

    The code is:

    @equals(formatDateTime(items('Apply_to_each')?['LastModified'], 'yyyy-MM-dd'),adddays(utcnow('yyyy-MM-dd'),-30))

     

    Please check the following screenshot for a reference.

     1.PNG

     

     

    Best regards,

    Mabel Mao

  • Community Power Platform Member Profile Picture
    on at
    Re: Flow - OneDrive - Delete files older than 30Days in Folder

    Awesome, thanks for this.  I've set it up and will test when the test files I've placed in Onedrive are a few days old.  I'll change the older than threshold for testing only and let you know

  • Community Power Platform Member Profile Picture
    on at
    Re: Flow - OneDrive - Delete files older than 30Days in Folder

    Hi,

     

    So I've uploaded some files which are a day old and modified the time to this code but the flow has not deleted any of the files and the condition comes back as false for each file.

     

    @equals(formatDateTime(items('Apply_to_each')?['LastModified'], 'yyyy-MM-dd'), adddays(utcnow('yyyy-MM-dd'), -1))

    flow.png

     

     

  • ScottShearer Profile Picture
    25,268 Most Valuable Professional on at
    Re: Flow - OneDrive - Delete files older than 30Days in Folder

    Just so I am clear, did you upload the documents yesterday?

     

    Can you post a screen shot of the files in the library showing the last modified date?

  • Community Power Platform Member Profile Picture
    on at
    Re: Flow - OneDrive - Delete files older than 30Days in Folder

    flow2.png

     

     

  • v-yamao-msft Profile Picture
    on at
    Re: Flow - OneDrive - Delete files older than 30Days in Folder

    Hi @Anonymous,

     

    I modified the flow configuration, please check the following flow configuration.

     

    First, use the action initialize variable, set Name as LastModified, Type as String.

     

    Then the action List files in folder. Specify the folder from which you want to get files.

     

    Then under Apply to each, add the action Set variable, select dynamic content Last Modified Time for the Value field.

     

    Then use a Compose action to format the LastModified time. The code is:

    formatDateTime(variables('LastModified'),'yyyy-MM-dd')

     

    Then configure the Condition using code likes below:

    @equals(outputs('Compose_2'),formatDateTime(adddays(utcnow(),-3),'yyyy-MM-dd'))

     

    Under the If Yes branch, add the Delete file action, select dynamic content Id from the trigger.

    1.PNG

     

     

    Please try again with it on your side.

     

    Best regards,

    Mabel Mao

  • Verified answer
    Community Power Platform Member Profile Picture
    on at
    Re: Flow - OneDrive - Delete files older than 30Days in Folder

    Hi,

     

    flow3.png
    Still nothing, it's pulled in the LastModified date/time but the conditions are still false so no deleted files

  • Verified answer
    v-yamao-msft Profile Picture
    on at
    Re: Flow - OneDrive - Delete files older than 30Days in Folder

    Hi @Anonymous,

     

    It seems that the Compose doesn't return repect value. Please enter the function under the Expression tab then check the return value. It should return a date time value but not the function itself.

     

    Best regards,

    Mabel Mao

  • Community Power Platform Member Profile Picture
    on at
    Re: Flow - OneDrive - Delete files older than 30Days in Folder

    Yep that worked but the flow failed as it tried to delete subfolders on top of the files in that subfolder

     

    {
      "status"400,
      "message""Resource : '481915922BF7857F!71255' is a directory. This API works only on files",
      "source""api.connectorp.svc.ms"
    }

  • Community Power Platform Member Profile Picture
    on at
    Re: Flow - OneDrive - Delete files older than 30Days in Folder

    Anyone found a solution for this - seems struggling to get it working as I don't understand the condition statement.

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 462 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 456 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard