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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / When a new file is cre...
Power Automate
Answered

When a new file is created, automatically delete a file

(0) ShareShare
ReportReport
Posted on by 75
Hi everyone - 
I am building a flow that will automatically upload an attachment to a Teams folder based upon the parameters that I define.  The attachment will always be from the same sender, it will always be sent on a Tuesday, and it will always have the file name beginning with Offer Data Report (no HR) for Recruiting YYYY-MM-DD-HH-mm.xlsx.  The date at the end of the file name reflects the Tuesday on which the report was automatically created.  I have figured out how to automatically get the email attachment into the Teams folder using the flow below:
The second part is what I am having trouble with...when a new file is created in the Teams folder, I want the file from the previous Tuesday to be deleted (my goal is to only have the most updated version of the report in the Teams folder at any given time).  I thought that using a Get files (properties only) action and a Delete files action would be the best way to go.  This is how far I've gotten with that: 
Does anyone have suggestions on the expression I would put in the Filter Query to only pull the files that were created prior to the date of the most recent file upload?  Again, this will always be on a Tuesday and the file name will always contain Offer Data Report (no HR) for Recruiting.  
 
Thank you!
Categories:
I have the same question (0)
  • JD-03091828-0 Profile Picture
    75 on at
    Hello - thank you very much for the clarification.  I took a bit of a different approach as I was having trouble getting the filter query to work and added a List Folder and Condition step: 
     
    If both conditions are met, nothing will happen.  If conditions are not met, the file will be deleted.
     
     
  • Verified answer
    SudeepGhatakNZ Profile Picture
    14,394 Most Valuable Professional on at
    This is what I meant.
     
  • JD-03091828-0 Profile Picture
    75 on at
    @SudeepGhatakNZ - thank you - this is helpful!  I think that the startsWith function is wanting a string for the column name.  What would I need to do to convert the column name into a string?  And, would I put this statement into Filter Query or into Limit Columns by View?  I will need to use this function as the flow is not running due to the number of items in the list view threshold.  Thank you!
  • Suggested answer
    SudeepGhatakNZ Profile Picture
    14,394 Most Valuable Professional on at

    Hi,

    Use the Get files (properties only) action with the OrderBy property to sort files by the Created date in descending order. This will allow you to pull the most recent file first. Set the Top Count to 1 (to only retrieve the most recent file).

    To only pull files matching the naming pattern. Use:
    startswith(Name, 'Offer Data Report (no HR) for Recruiting')

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
David_MA Profile Picture

David_MA 245 Super User 2025 Season 2

#2
Expiscornovus Profile Picture

Expiscornovus 207 Most Valuable Professional

#3
trice602 Profile Picture

trice602 190 Super User 2025 Season 2

Last 30 days Overall leaderboard