How to delete files in sharepoint based on upload date using power automate

Harshit 0 Reputation points
2024-06-26T11:05:16.41+00:00

I designed two flows. First one upload attachments from outlook in a folder in sharepoint. Second flow is scheduled flow which runs every day at 4 AM in morning, it deletes previous day attachments that will make place for new attachments, but the attachments uplaoded on the month end should be preserved. Basically i want the attachment files received on month end.

I thought of doing it by using "Get file metadata" but it gives last modified date but not the creation date.

So is this possible to delete files from sharepoint based on created date or uplaod date using automate so that i can delete other attachments on daily basis but keep attachment received on month end using condition.

Does anyone have any idea about this ?

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,810 questions
Outlook Management
Outlook Management
Outlook: A family of Microsoft email and calendar products.Management: The act or process of organizing, handling, directing or controlling something.
5,272 questions
SharePoint Workflow
SharePoint Workflow
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Workflow: An orchestrated and repeatable pattern of business activity, enabling data transformation, service provision, and information retrieval.
599 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Xyza Xue_MSFT 25,466 Reputation points Microsoft Vendor
    2024-06-27T06:08:47.27+00:00

    Hi @Harshit ,

    Thank you for posting in this community.

    Since Power Automate is currently not supported in the Q&A forum, and my knowledge of it is limited, below is a workaround based on my knowledge, if this solves your problem that would be great. If this does not solve your problem, or if you are experiencing a more complex issue, it is recommended that you start a new discussion via the Power Automate Community to get more targeted support.

    If you want to delete a file based on its created date but keep files received on month end using condition, you can refer to the following screenshots.

    Flow in details:

    1.Add a "Get files (properties only)" action to retrieve the metadata of the files.

    2.Add two conditional expressions to delete a file when its creation time is yesterday and the creation time is not the end of the month.

    The Expression on the left of the first Condition: 

    formatDateTime(item()?['Created'],'yyyy-MM-dd')
    

    The Expression on the right of the first Condition: 

    addDays(utcNow(),1,'yyyy-MM-dd')
    

    The Expression on the left of the second Condition: 

    formatDateTime(item()?['Created'],'yyyy-MM-dd')
    

    The Expression on the right of the second Condition: 

    addDays(startOfMonth(addDays(startOfMonth(utcNow()),32)),-1)
    

    User's image

    Hope the information can help you.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.